{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`The Art of Prompt Design`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Retrevial Augmented Generation (RAG)\n",
    "\n",
    "In this notebook we create an example of a simple chatbot that searches the web in order to respond.  \n",
    "This is only meant as an example, and is not meant to be a state-of-the-art chatbot. *(and this notebook is a work in progress)*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "import guidance\n",
    "from guidance import models, gen, select, substring, string, prefix_tree, regex, user, assistant, system"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "llama2 = models.LlamaCpp(\"/home/marcotcr_google_com/work/models/llama-2-13b-chat.Q6_K.gguf\", n_gpu_layers=-1, n_ctx=4096)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "llama2 = models.OpenAI(\"gpt-3.5-turbo\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Code for calling a search engine (Bing)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You need to set up a bing api project (it's free), and change the api_key file path below"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "import diskcache\n",
    "import pathlib\n",
    "import requests\n",
    "import html\n",
    "from urllib.parse import urlparse\n",
    "import urllib.parse\n",
    "import io\n",
    "import html\n",
    "import html.parser\n",
    "\n",
    "curr_dir = './'\n",
    "_bing_cache = diskcache.Cache(f\"{curr_dir}/../bing.diskcache\")\n",
    "\n",
    "with open(os.path.expanduser('/home/scottlundberg_google_com/.bing_api_key'), 'r') as file:\n",
    "    subscription_key = file.read().replace('\\n', '')\n",
    "\n",
    "class MLStripper(html.parser.HTMLParser):\n",
    "    def __init__(self):\n",
    "        super().__init__()\n",
    "        self.reset()\n",
    "        self.strict = False\n",
    "        self.convert_charrefs = True\n",
    "        self.text = io.StringIO()\n",
    "    def handle_data(self, d):\n",
    "        self.text.write(d)\n",
    "    def get_data(self):\n",
    "        return self.text.getvalue()\n",
    "\n",
    "def strip_tags(html):\n",
    "    s = MLStripper()\n",
    "    s.feed(html)\n",
    "    return s.get_data()\n",
    "\n",
    "def bing_search(search_terms, count=10):\n",
    "    if type(search_terms) == str:\n",
    "        search_terms = [search_terms]\n",
    "    search_url = \"https://api.bing.microsoft.com/v7.0/search\"\n",
    "\n",
    "    headers = {\"Ocp-Apim-Subscription-Key\": subscription_key}\n",
    "    search_results = []\n",
    "    for search_term in search_terms:\n",
    "        params = {\"q\": search_term, \"textDecorations\": True, \"textFormat\": \"HTML\", \"cout\": count}\n",
    "        params_key = search_term + \"-___-\" + str(count)\n",
    "        if params_key not in _bing_cache or \"webPages\" not in _bing_cache[params_key]:\n",
    "            response = requests.get(search_url, headers=headers, params=params)\n",
    "            response.raise_for_status()\n",
    "            _bing_cache[params_key] = response.json()\n",
    "        data = _bing_cache[params_key][\"webPages\"][\"value\"]\n",
    "        for r in data:\n",
    "            r[\"snippet_text\"] = strip_tags(r[\"snippet\"])\n",
    "        search_results.extend(data)\n",
    "    return search_results\n",
    "def top_snippets(query, n=3):\n",
    "    results = bing_search(query, count=n)[:n]\n",
    "    return [{'title': x['name'], 'snippet': x['snippet_text']} for x in results]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1] President of the United States - Wikipedia\n",
      "The president of the United States ( POTUS) [A] is the head of state and head of government of the United States of America. The president directs the executive branch of the federal government and is the commander-in-chief of the United States Armed Forces . The power of the presidency has grown substantially [11] since the first president ...\n",
      "\n",
      "[2] Joe Biden: The President | The White House\n",
      "Joe Biden The President Download Official Portrait President Biden represented Delaware for 36 years in the U.S. Senate before becoming the 47th Vice President of the United States. As...\n",
      "\n",
      "[3] Presidents, vice presidents, and first ladies | USAGov\n",
      "U.S. facts and figures Presidents, vice presidents, and first ladies Presidents, vice presidents, and first ladies Learn about the duties of president, vice president, and first lady of the United States. Find out how to contact and learn more about current and past leaders. President of the United States Vice president of the United States\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "def format_snippets(snippets, start=1):\n",
    "    ret = ''\n",
    "    for i, s in enumerate(snippets, start=start):\n",
    "        title = s['title']\n",
    "        snippet = s['snippet']\n",
    "        ret += f'[{i}] {title}\\n'\n",
    "        ret += f'{snippet}\\n\\n'\n",
    "    return ret\n",
    "        \n",
    "print(format_snippets(top_snippets('current us president')))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Guidance code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "from guidance import gen, select, silent, capture, Tool, one_or_more, any_char, commit_point\n",
    "import collections"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "First, let's write an initial prompt with some few-shot examples of REACT.  \n",
    "This prompt is trying to get the model to:\n",
    "1. Search the web to find answers to questions\n",
    "2. Read snippets, extract quotes that are relevant (to minimize hallucination)\n",
    "3. Do extra searches if need\n",
    "4. Print all of the quotes it gathered (from all search queries)\n",
    "5. Answer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "@guidance\n",
    "def init_system(lm):\n",
    "    # silent makes this whole thing not appear in the jupyter notebook visualization\n",
    "    with silent():\n",
    "        with system():\n",
    "            lm += '''\\\n",
    "            You are a nice chatbot that answers users' queries. Whenever you get a question, you run a loop of [Thought, Act, Observation] until you hit a response, where Act is one of (search, respond, extract_quotes, list_quotes).\n",
    "            You have a storehouse of facts, but you *always* search if you need information that depends on current events, since what you know may be out-of-date.\n",
    "            After searching, if you find information in the snippets, you should extract quotes.\n",
    "            If you need, you can make multiple searches.\n",
    "            You should only ask the user for more information is their question is ambiguous.\n",
    "            If the snippets are ambiguous or don't contain enough information, you should make additional searches instead of asking the user.\n",
    "            Here are some example interactions:\n",
    "            ---\n",
    "            User: Who is the current president of the US?\n",
    "            Thought: Since the president may have changed, my information may be out of date. Thus, I need to search the web for this.\n",
    "            Act: search(current US president)\n",
    "            Observation: \n",
    "            [1] Joe Biden: The President | The White House\n",
    "            Joe Biden The President House — with thousands of train rides in between Download Official Portrait President Biden represented Delaware for 36 years in the U.S. Senate before becoming the...\n",
    "\n",
    "            [2] President of the United States - Wikipedia\n",
    "            The president of the United States ( POTUS) [A] is the head of state and head of government of the United States. The president directs the executive branch of the federal government and is the commander-in-chief of the United States Armed Forces . The power of the presidency has grown substantially [11] since the first president, George ...\n",
    "\n",
    "            [3] List of presidents of the United States - Wikipedia\n",
    "            Grover Cleveland served two non-consecutive terms and is therefore counted as the 22nd and 24th president of the United States, giving rise to the discrepancy between the number of presidencies and the number of persons who have served as president. [5] The incumbent president is Joe Biden. [6]\n",
    "            \n",
    "            Thought: Snippets [1] and [3] clearly indicate that Joe Biden is the current president.\n",
    "            Act: extract_quotes()\n",
    "            Question: Who is the current president of the US?\n",
    "            Relevant quotes from the snippets:\n",
    "            - Snippet 1: \"Joe Biden: The President | White House\"\n",
    "            - Snippet 3: \"The incumbent president is Joe Biden\"\n",
    "            Thought: I have enough information to respond, so I will list the quotes and then respond.\n",
    "            Act: list_quotes()\n",
    "            Question: Who is the current president of the US?\n",
    "            Query: current US president\n",
    "            - Snippet 1: \"Joe Biden: The President | White House\"\n",
    "            - Snippet 3: \"The incumbent president is Joe Biden\"\n",
    "            Thought: I will write a response now.\n",
    "            Act: respond(The current president of the US is Joe Biden)\n",
    "            ---\n",
    "            User: What is the capital of France?\n",
    "            Thought: It is really unlikely that the capital of France changed since my database was last updated. So, I don't need to search the web, and can respond.\n",
    "            Act: respond(The capital of France is Paris)\n",
    "            ---\n",
    "            User: What is the capital of Georgia?\n",
    "            Thought: The user can be asking about Georgia the country or Georgia the state. I should confirm which one before issuing a final response\n",
    "            Act: respond(Do you mean the state or the country?)\n",
    "            Observation:\n",
    "            User: The state\n",
    "            Thought: The capital of Georgia probably didn't change since my database was last updated, so I can respond. \n",
    "            Act: respond(The capital of Georgia is Atlanta)\n",
    "            ---\n",
    "            User: Who is richer, Messi or Ronaldinho Gaucho?\n",
    "            Thought: To answer this, I will need to search for each of their net worths, and then compare.\n",
    "            Act: search(Ronaldinho Gaucho net worth)\n",
    "            Observation:\n",
    "            [1] Ronaldinho&#39;s Net Worth (Updated 2023) | Wealthy Gorilla\n",
    "            Introduction As of September 2023, Ronaldinho’s net worth is estimated to be roughly $90 Million. Ronaldo de Assis Moreira, better known as Ronaldinho, is a Brazilian former professional footballer and ambassador for Barcelona. from Porto Alegre. He is regarded to be one of the best football players of all time. Early Life\n",
    "\n",
    "            [2] Ronaldinho Net Worth | Celebrity Net Worth\n",
    "            Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million. Ronaldinho was once considered to be the best soccer player in the world. He was twice the...\n",
    "\n",
    "            [3] Ronaldinho Net Worth: 2022, Career, House, Cars &amp; Lifestyle - Players Bio\n",
    "            A Brazilian legend, Ronaldinho has an outstanding net worth of $90 million. Even at his time, this sum was as impressive as it is now. Ronaldinho is $90 million rich because of football. But let me stop you right there. It’s not in everybody’s forte to excel as the Brazilian did.\n",
    "            \n",
    "            Thought: All snippets seem to talk about his net worth.\n",
    "            Act: extract_quotes()\n",
    "            Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
    "            Relevant quotes from the snippets:\n",
    "            - Snippet 1: \"Ronaldinho’s net worth is estimated to be roughly $90 Million\"\n",
    "            - Snippet 2: \"Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million.\"\n",
    "            - Snippet 3: \"Ronaldinho has an outstanding net worth of $90 million\"\n",
    "            Thought: I still need to search for Messi's net worth and compare\n",
    "            Act: search(messi net worth)\n",
    "            Observation:\n",
    "            [1] Lionel Messi - Forbes\n",
    "            $130M 2023 The World's Highest-Paid Athletes Earnings as of 5/16/23 Photo by Antonio Borga/Eurasia Sport Images/Getty Images About Lionel Messi Messi claimed the Ballon d'Or as the world's best...\n",
    "\n",
    "            [2] Lionel Messi Net Worth: How the Soccer Star Makes and Spends ... - Insider\n",
    "            CHANDAN KHANNA/Getty Images Messi took home a mind-boggling $65 million in on-field earnings over the last year — more than all but one soccer player on the planet. His Inter Miami salary alone is worth $20,446,667 annually, per AP News, which means he earns roughly $393,000 per week or $56,000 per day from the Major League Soccer club.\n",
    "\n",
    "            [3] Lionel Messi Net Worth\n",
    "            $600 Million Salary: $75 Million Date of Birth: Jun 24, 1987 (36 years old) Place of Birth: Rosario, Argentina Gender: Male Height: 5 ft 6 in (1.69 m) Profession: Football player Nationality:...\n",
    "\n",
    "            Thought: Snippet 1 says $130M, but it may be referring to other athletes based on the rest of the snippet.\n",
    "            Snippets 2 and 3 talk about his salary (with contradictory numbers), but not his net worth. Thus, there are no relevant quotes here, and I should make another search.\n",
    "            I will make the search narrower using quotes.\n",
    "            Act: search(messi \"net worth\")\n",
    "            Observation:\n",
    "            [1] Lionel Messi - Forbes\n",
    "            About Lionel Messi. Messi claimed the Ballon d'Or as the world's best soccer player for a record seventh time in 2021, putting him two ahead of his rival Cristiano Ronaldo. He transferred to Paris ...\n",
    "\n",
    "            [2] Lionel Messi Net Worth: How the Soccer Star Makes and Spends ... - Insider\n",
    "            His net worth is an eye-watering $600 million. Leo Messi of Paris Saint-Germain looks on during warmup before the Ligue 1 Uber Eats match between Paris Saint Germain and ESTAC Troyes at Parc des Princes on May 08, 2022 in Paris, France. Photo by Aurelien Meunier - PSG/PSG via Getty Images That's according to Celebrity Net Worth. Advertisement\n",
    "\n",
    "            [3] Lionel Messi&#39;s new $650,000 Bentley shows of his massive net worth\n",
    "            In 2023, Messi's net worth is a staggering $620 million, securing his place as the third-highest-paid athlete globally. A recent addition to Messi's extravagant lifestyle is a sleek Bentley...\n",
    "\n",
    "            Thought: Snippets 2 and 3 list his net worth.\n",
    "            Act: extract_quotes()\n",
    "            Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
    "            Relevant quotes from the snippets:\n",
    "            - Snippet 2: \"His net worth is an eye-watering $600 million\"\n",
    "            - Snippet 3: \"In 2023, Messi's net worth is a staggering $620 million\"\n",
    "            Thought: I have all the information I need to respond, so I'll list the quotes and then respond.\n",
    "            Act: list_quotes()\n",
    "            Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
    "            Query: Ronaldinho Gaucho net worth\n",
    "            - Snippet 1: \"Ronaldinho’s net worth is estimated to be roughly $90 Million\"\n",
    "            - Snippet 2: \"Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million.\"\n",
    "            - Snippet 3: \"Ronaldinho has an outstanding net worth of $90 million\"\n",
    "            Query: messi \"net worth\"\n",
    "            - Snippet 2: \"His net worth is an eye-watering $600 million\"\n",
    "            - Snippet 3: \"In 2023, Messi's net worth is a staggering $620 million\"\n",
    "            Thought: I will write a response now.\n",
    "            Act: respond(Messi has an estimated net worth between $600 and $620 million, while Ronaldinho has an estimated net worth of $90 million. Thus, Messi is richer)\n",
    "            '''\n",
    "    return lm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now let's define the functions that search and extract quotes:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "@guidance\n",
    "def search(lm, query):\n",
    "    # Setting this for later use\n",
    "    lm = lm.set('query', query)\n",
    "    # This is where search actually gets called\n",
    "    lm = lm.set('snippets', format_snippets(top_snippets(query)))\n",
    "    lm += '\\nObservation:\\n' + lm['snippets']\n",
    "    return lm\n",
    "\n",
    "@guidance\n",
    "def extract_quotes(lm):\n",
    "    query = lm['query']\n",
    "    snippets = lm['snippets'].split('\\n\\n')[:-1]\n",
    "    snippet_substrings = [substring(x) for x in snippets]\n",
    "    # By default we have 3 snippets. The model can pick (1) which snippets it's going to quote, and then (2) a substring of that snippet\n",
    "    snippet = '- Snippet ' + select([\n",
    "        '1: \"' + snippet_substrings[0] + '\"',\n",
    "        '2: \"' + snippet_substrings[1] + '\"',\n",
    "        '3: \"' + snippet_substrings[2] + '\"',]) + '\\n'\n",
    "    # We can do one or more quotes\n",
    "    lm += capture(one_or_more(snippet), name='temp_gen')\n",
    "    # We save all of the quotes so that we can print them at the end\n",
    "    current_quotes = lm.get('current_quotes', '')\n",
    "    current_quotes += f'''Query: {query}\\n{lm['temp_gen']}'''\n",
    "    lm = lm.set('current_quotes', current_quotes)\n",
    "    return lm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here is an example of search, and how it adds snippets to an lm:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style='margin: 0px; padding: 0px; vertical-align: middle; padding-left: 8px; margin-left: -8px; border-radius: 0px; border-left: 1px solid rgba(127, 127, 127, 0.2); white-space: pre-wrap; font-family: ColfaxAI, Arial; font-size: 15px; line-height: 23px;'>\n",
       "Observation:\n",
       "[1] President of the United States - Wikipedia\n",
       "t. e. The president of the United States ( POTUS) [A] is the head of state and head of government of the United States of America. The president directs the executive branch of the federal government and is the commander-in-chief of the United States Armed Forces . The power of the presidency has grown substantially [11] since the first ...\n",
       "\n",
       "[2] list of presidents of the United States - Encyclopedia Britannica\n",
       "As the head of the government of the United States, the president is arguably the most powerful government official in the world. The president is elected to a four-year term via an electoral college system. Since the Twenty-second Amendment was adopted in 1951, the American presidency has been\n",
       "\n",
       "[3] Presidents, vice presidents, and first ladies | USAGov\n",
       "U.S. facts and figures Presidents, vice presidents, and first ladies Presidents, vice presidents, and first ladies Learn about the duties of president, vice president, and first lady of the United States. Find out how to contact and learn more about current and past leaders. President of the United States Vice president of the United States\n",
       "\n",
       "</pre>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "lm = llama2 + search('current use president')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "And here is an example of extract_quotes:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style='margin: 0px; padding: 0px; vertical-align: middle; padding-left: 8px; margin-left: -8px; border-radius: 0px; border-left: 1px solid rgba(127, 127, 127, 0.2); white-space: pre-wrap; font-family: ColfaxAI, Arial; font-size: 15px; line-height: 23px;'>\n",
       "Observation:\n",
       "[1] President of the United States - Wikipedia\n",
       "t. e. The president of the United States ( POTUS) [A] is the head of state and head of government of the United States of America. The president directs the executive branch of the federal government and is the commander-in-chief of the United States Armed Forces . The power of the presidency has grown substantially [11] since the first ...\n",
       "\n",
       "[2] list of presidents of the United States - Encyclopedia Britannica\n",
       "As the head of the government of the United States, the president is arguably the most powerful government official in the world. The president is elected to a four-year term via an electoral college system. Since the Twenty-second Amendment was adopted in 1951, the American presidency has been\n",
       "\n",
       "[3] Presidents, vice presidents, and first ladies | USAGov\n",
       "U.S. facts and figures Presidents, vice presidents, and first ladies Presidents, vice presidents, and first ladies Learn about the duties of president, vice president, and first lady of the United States. Find out how to contact and learn more about current and past leaders. President of the United States Vice president of the United States\n",
       "\n",
       "Now I will extract quotes relevant to the question &quot;What does the president do?&quot;\n",
       "</pre>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "ename": "ValueError",
     "evalue": "The OpenAI model gpt-3.5-turbo is a Chat-based model and requires role tags in the prompt!             Make sure you are using guidance context managers like `with system():`, `with user():` and `with assistant():`             to appropriately format your guidance program for this type of model.",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[9], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mlm\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mNow I will extract quotes relevant to the question \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mWhat does the president do?\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m  \u001b[49m\u001b[43mextract_quotes\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
      "File \u001b[0;32m~/projects/guidance/guidance/models/_model.py:300\u001b[0m, in \u001b[0;36mModel.__add__\u001b[0;34m(self, value)\u001b[0m\n\u001b[1;32m    296\u001b[0m     out \u001b[38;5;241m=\u001b[39m lm\u001b[38;5;241m.\u001b[39m_run_stateless(value)\n\u001b[1;32m    298\u001b[0m \u001b[38;5;66;03m# run stateful functions\u001b[39;00m\n\u001b[1;32m    299\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 300\u001b[0m     out \u001b[38;5;241m=\u001b[39m \u001b[43mvalue\u001b[49m\u001b[43m(\u001b[49m\u001b[43mlm\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    301\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m out \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m    302\u001b[0m         \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mA guidance function did not return a model object! Did you forget to return the new lm at the end of your function?\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
      "File \u001b[0;32m~/projects/guidance/guidance/_grammar.py:45\u001b[0m, in \u001b[0;36mStatefulFunction.__call__\u001b[0;34m(self, model)\u001b[0m\n\u001b[1;32m     44\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__call__\u001b[39m(\u001b[38;5;28mself\u001b[39m, model):\n\u001b[0;32m---> 45\u001b[0m     \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mf\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmodel\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
      "Cell \u001b[0;32mIn[7], line 21\u001b[0m, in \u001b[0;36mextract_quotes\u001b[0;34m(lm)\u001b[0m\n\u001b[1;32m     16\u001b[0m snippet \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m- Snippet \u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;241m+\u001b[39m select([\n\u001b[1;32m     17\u001b[0m     \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m1: \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;241m+\u001b[39m snippet_substrings[\u001b[38;5;241m0\u001b[39m] \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[1;32m     18\u001b[0m     \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m2: \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;241m+\u001b[39m snippet_substrings[\u001b[38;5;241m1\u001b[39m] \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[1;32m     19\u001b[0m     \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m3: \u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;241m+\u001b[39m snippet_substrings[\u001b[38;5;241m2\u001b[39m] \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m'\u001b[39m,]) \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m     20\u001b[0m \u001b[38;5;66;03m# We can do one or more quotes\u001b[39;00m\n\u001b[0;32m---> 21\u001b[0m \u001b[43mlm\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mcapture\u001b[49m\u001b[43m(\u001b[49m\u001b[43mone_or_more\u001b[49m\u001b[43m(\u001b[49m\u001b[43msnippet\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mname\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mtemp_gen\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m     22\u001b[0m \u001b[38;5;66;03m# We save all of the quotes so that we can print them at the end\u001b[39;00m\n\u001b[1;32m     23\u001b[0m current_quotes \u001b[38;5;241m=\u001b[39m lm\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mcurrent_quotes\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m'\u001b[39m)\n",
      "File \u001b[0;32m~/projects/guidance/guidance/models/_model.py:296\u001b[0m, in \u001b[0;36mModel.__add__\u001b[0;34m(self, value)\u001b[0m\n\u001b[1;32m    294\u001b[0m \u001b[38;5;66;03m# run stateless functions (grammar nodes)\u001b[39;00m\n\u001b[1;32m    295\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(value, StatelessFunction):\n\u001b[0;32m--> 296\u001b[0m     out \u001b[38;5;241m=\u001b[39m \u001b[43mlm\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_run_stateless\u001b[49m\u001b[43m(\u001b[49m\u001b[43mvalue\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    298\u001b[0m \u001b[38;5;66;03m# run stateful functions\u001b[39;00m\n\u001b[1;32m    299\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m    300\u001b[0m     out \u001b[38;5;241m=\u001b[39m value(lm)\n",
      "File \u001b[0;32m~/projects/guidance/guidance/models/_model.py:459\u001b[0m, in \u001b[0;36mModel._run_stateless\u001b[0;34m(lm, stateless_function, temperature, top_p, n)\u001b[0m\n\u001b[1;32m    457\u001b[0m delayed_bytes \u001b[38;5;241m=\u001b[39m \u001b[38;5;124mb\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m    458\u001b[0m \u001b[38;5;66;03m# last_is_generated = False\u001b[39;00m\n\u001b[0;32m--> 459\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m new_bytes, is_generated, new_bytes_prob, capture_groups, capture_group_log_probs, new_token_count \u001b[38;5;129;01min\u001b[39;00m gen_obj:\n\u001b[1;32m    460\u001b[0m \n\u001b[1;32m    461\u001b[0m     \u001b[38;5;66;03m# we make everything full probability if we are not computing uncertainty\u001b[39;00m\n\u001b[1;32m    462\u001b[0m     \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m lm\u001b[38;5;241m.\u001b[39mcompute_log_probs:\n\u001b[1;32m    463\u001b[0m         new_bytes_prob \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1.0\u001b[39m\n",
      "File \u001b[0;32m~/projects/guidance/guidance/models/_model.py:778\u001b[0m, in \u001b[0;36mModel.__call__\u001b[0;34m(self, grammar, max_tokens, n, top_p, temperature, ensure_bos_token)\u001b[0m\n\u001b[1;32m    776\u001b[0m grammar_temp \u001b[38;5;241m=\u001b[39m parser\u001b[38;5;241m.\u001b[39mnext_byte_temperature()\n\u001b[1;32m    777\u001b[0m current_temp \u001b[38;5;241m=\u001b[39m grammar_temp \u001b[38;5;28;01mif\u001b[39;00m grammar_temp \u001b[38;5;241m>\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m temperature \u001b[38;5;66;03m# we prefer to use the grammar temp when it is specified\u001b[39;00m\n\u001b[0;32m--> 778\u001b[0m logits \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_get_logits\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtoken_ids\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mparser\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbytes\u001b[49m\u001b[43m[\u001b[49m\u001b[43mstart_pos\u001b[49m\u001b[43m:\u001b[49m\u001b[43mforced_pos\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcurrent_temp\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m    780\u001b[0m \u001b[38;5;66;03m# if requested we compute the log probabilities so we can track the probabilities of each node\u001b[39;00m\n\u001b[1;32m    781\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcompute_log_probs:\n",
      "File \u001b[0;32m~/projects/guidance/guidance/models/_remote.py:250\u001b[0m, in \u001b[0;36mRemote._get_logits\u001b[0;34m(self, token_ids, forced_bytes, current_temp)\u001b[0m\n\u001b[1;32m    248\u001b[0m new_bytes \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_shared_state[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdata_queue\u001b[39m\u001b[38;5;124m\"\u001b[39m]\u001b[38;5;241m.\u001b[39mget_nowait()\n\u001b[1;32m    249\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(new_bytes, \u001b[38;5;167;01mException\u001b[39;00m):\n\u001b[0;32m--> 250\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m new_bytes\n\u001b[1;32m    252\u001b[0m \u001b[38;5;66;03m# if we are at the end of the generation then we try again allowing for early token stopping\u001b[39;00m\n\u001b[1;32m    253\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(new_bytes) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n",
      "File \u001b[0;32m~/projects/guidance/guidance/models/_remote.py:106\u001b[0m, in \u001b[0;36mRemote._start_generator_stream\u001b[0;34m(self, generator)\u001b[0m\n\u001b[1;32m    104\u001b[0m first_iteration \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mTrue\u001b[39;00m\n\u001b[1;32m    105\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m: \n\u001b[0;32m--> 106\u001b[0m     \u001b[38;5;28;01mfor\u001b[39;00m chunk \u001b[38;5;129;01min\u001b[39;00m generator:\n\u001b[1;32m    107\u001b[0m         logger\u001b[38;5;241m.\u001b[39mdebug(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mGot chunk: \u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m+\u001b[39m \u001b[38;5;28mstr\u001b[39m(chunk))\n\u001b[1;32m    108\u001b[0m         \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(chunk) \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m:\n",
      "File \u001b[0;32m~/projects/guidance/guidance/models/_openai.py:165\u001b[0m, in \u001b[0;36mOAIChatMixin._generator\u001b[0;34m(self, prompt, temperature)\u001b[0m\n\u001b[1;32m    162\u001b[0m \u001b[38;5;66;03m# Add nice exception if no role tags were used in the prompt.\u001b[39;00m\n\u001b[1;32m    163\u001b[0m \u001b[38;5;66;03m# TODO: Move this somewhere more general for all chat models?\u001b[39;00m\n\u001b[1;32m    164\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m messages \u001b[38;5;241m==\u001b[39m []:\n\u001b[0;32m--> 165\u001b[0m     \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mThe OpenAI model \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel_name\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m is a Chat-based model and requires role tags in the prompt! \u001b[39m\u001b[38;5;130;01m\\\u001b[39;00m\n\u001b[1;32m    166\u001b[0m \u001b[38;5;124m    Make sure you are using guidance context managers like `with system():`, `with user():` and `with assistant():` \u001b[39m\u001b[38;5;130;01m\\\u001b[39;00m\n\u001b[1;32m    167\u001b[0m \u001b[38;5;124m    to appropriately format your guidance program for this type of model.\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m    169\u001b[0m \u001b[38;5;66;03m# update our shared data state\u001b[39;00m\n\u001b[1;32m    170\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_reset_shared_data(prompt[:pos], temperature)\n",
      "\u001b[0;31mValueError\u001b[0m: The OpenAI model gpt-3.5-turbo is a Chat-based model and requires role tags in the prompt!             Make sure you are using guidance context managers like `with system():`, `with user():` and `with assistant():`             to appropriately format your guidance program for this type of model."
     ]
    }
   ],
   "source": [
    "lm + 'Now I will extract quotes relevant to the question \"What does the president do?\"\\n'+  extract_quotes()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now let's write functions to start / restart the chat, and to do the react loop:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "@guidance\n",
    "def chat_search(lm, query):\n",
    "    with user():\n",
    "        lm += f'User: {query}'\n",
    "        lm = lm.set('user_query', query)\n",
    "    with assistant():\n",
    "        lm += react_loop()\n",
    "    return lm\n",
    "\n",
    "@guidance\n",
    "def react_loop(lm):\n",
    "    while True:\n",
    "        lm += 'Thought: ' + gen('thought', list_append=True, stop='Act:')\n",
    "        lm += 'Act: ' + select(['search', 'respond', 'extract_quotes', 'list_quotes'], name='action')\n",
    "        action = lm['action']\n",
    "        if action == 'search':\n",
    "            # generate the search query\n",
    "            lm += f'''({gen(name='arg', stop=')')})\\n'''\n",
    "            # search the web and paste result into the prompt\n",
    "            lm += search(lm['arg'])\n",
    "        if action == 'respond':\n",
    "            # generate the response and stop the loop\n",
    "            lm += f'''({gen(name='arg', stop=')')})\\n'''\n",
    "            break\n",
    "        if action == 'extract_quotes':\n",
    "            lm += '()\\n'\n",
    "            lm += 'Question: ' + lm['user_query'] + '\\n'\n",
    "            lm += 'Relevant quotes from the snippets:\\n'\n",
    "            lm += extract_quotes()\n",
    "        if action == 'list_quotes':\n",
    "            lm += '()\\n'\n",
    "            lm += 'Question: ' + lm['user_query'] + '\\n'\n",
    "            # Just paste all of the quotes we gathered throughout the loop\n",
    "            lm += lm['current_quotes']\n",
    "    return lm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style='margin: 0px; padding: 0px; padding-left: 8px; margin-left: -8px; border-radius: 0px; border-left: 1px solid rgba(127, 127, 127, 0.2); white-space: pre-wrap; font-family: ColfaxAI, Arial; font-size: 15px; line-height: 23px;'><div style='display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;'><div style='flex: 0 0 80px; opacity: 0.5;'>system</div><div style='flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;'><div style='display: inline-block; cursor: pointer; opacity: 0.5; width: 2px; margin-left: -2px;' onClick='this.nextSibling.style.display = \"inline\"; this.style.display = \"none\"'>&caron;</div><div style='display: none;'>You are a nice chatbot that answers users&#x27; queries. Whenever you get a question, you run a loop of [Thought, Act, Observation] until you hit a response, where Act is one of (search, respond, extract_quotes, list_quotes).\n",
       "You have a storehouse of facts, but you *always* search if you need information that depends on current events, since what you know may be out-of-date.\n",
       "After searching, if you find information in the snippets, you should extract quotes.\n",
       "If you need, you can make multiple searches.\n",
       "You should only ask the user for more information is their question is ambiguous.\n",
       "If the snippets are ambiguous or don&#x27;t contain enough information, you should make additional searches instead of asking the user.\n",
       "Here are some example interactions:\n",
       "---\n",
       "User: Who is the current president of the US?\n",
       "Thought: Since the president may have changed, my information may be out of date. Thus, I need to search the web for this.\n",
       "Act: search(current US president)\n",
       "Observation: \n",
       "[1] Joe Biden: The President | The White House\n",
       "Joe Biden The President House — with thousands of train rides in between Download Official Portrait President Biden represented Delaware for 36 years in the U.S. Senate before becoming the...\n",
       "\n",
       "[2] President of the United States - Wikipedia\n",
       "The president of the United States ( POTUS) [A] is the head of state and head of government of the United States. The president directs the executive branch of the federal government and is the commander-in-chief of the United States Armed Forces . The power of the presidency has grown substantially [11] since the first president, George ...\n",
       "\n",
       "[3] List of presidents of the United States - Wikipedia\n",
       "Grover Cleveland served two non-consecutive terms and is therefore counted as the 22nd and 24th president of the United States, giving rise to the discrepancy between the number of presidencies and the number of persons who have served as president. [5] The incumbent president is Joe Biden. [6]\n",
       "\n",
       "Thought: Snippets [1] and [3] clearly indicate that Joe Biden is the current president.\n",
       "Act: extract_quotes()\n",
       "Question: Who is the current president of the US?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet 1: &quot;Joe Biden: The President | White House&quot;\n",
       "- Snippet 3: &quot;The incumbent president is Joe Biden&quot;\n",
       "Thought: I have enough information to respond, so I will list the quotes and then respond.\n",
       "Act: list_quotes()\n",
       "Question: Who is the current president of the US?\n",
       "Query: current US president\n",
       "- Snippet 1: &quot;Joe Biden: The President | White House&quot;\n",
       "- Snippet 3: &quot;The incumbent president is Joe Biden&quot;\n",
       "Thought: I will write a response now.\n",
       "Act: respond(The current president of the US is Joe Biden)\n",
       "---\n",
       "User: What is the capital of France?\n",
       "Thought: It is really unlikely that the capital of France changed since my database was last updated. So, I don&#x27;t need to search the web, and can respond.\n",
       "Act: respond(The capital of France is Paris)\n",
       "---\n",
       "User: What is the capital of Georgia?\n",
       "Thought: The user can be asking about Georgia the country or Georgia the state. I should confirm which one before issuing a final response\n",
       "Act: respond(Do you mean the state or the country?)\n",
       "Observation:\n",
       "User: The state\n",
       "Thought: The capital of Georgia probably didn&#x27;t change since my database was last updated, so I can respond. \n",
       "Act: respond(The capital of Georgia is Atlanta)\n",
       "---\n",
       "User: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Thought: To answer this, I will need to search for each of their net worths, and then compare.\n",
       "Act: search(Ronaldinho Gaucho net worth)\n",
       "Observation:\n",
       "[1] Ronaldinho&amp;#39;s Net Worth (Updated 2023) | Wealthy Gorilla\n",
       "Introduction As of September 2023, Ronaldinho’s net worth is estimated to be roughly $90 Million. Ronaldo de Assis Moreira, better known as Ronaldinho, is a Brazilian former professional footballer and ambassador for Barcelona. from Porto Alegre. He is regarded to be one of the best football players of all time. Early Life\n",
       "\n",
       "[2] Ronaldinho Net Worth | Celebrity Net Worth\n",
       "Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million. Ronaldinho was once considered to be the best soccer player in the world. He was twice the...\n",
       "\n",
       "[3] Ronaldinho Net Worth: 2022, Career, House, Cars &amp;amp; Lifestyle - Players Bio\n",
       "A Brazilian legend, Ronaldinho has an outstanding net worth of $90 million. Even at his time, this sum was as impressive as it is now. Ronaldinho is $90 million rich because of football. But let me stop you right there. It’s not in everybody’s forte to excel as the Brazilian did.\n",
       "\n",
       "Thought: All snippets seem to talk about his net worth.\n",
       "Act: extract_quotes()\n",
       "Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet 1: &quot;Ronaldinho’s net worth is estimated to be roughly $90 Million&quot;\n",
       "- Snippet 2: &quot;Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million.&quot;\n",
       "- Snippet 3: &quot;Ronaldinho has an outstanding net worth of $90 million&quot;\n",
       "Thought: I still need to search for Messi&#x27;s net worth and compare\n",
       "Act: search(messi net worth)\n",
       "Observation:\n",
       "[1] Lionel Messi - Forbes\n",
       "$130M 2023 The World&#x27;s Highest-Paid Athletes Earnings as of 5/16/23 Photo by Antonio Borga/Eurasia Sport Images/Getty Images About Lionel Messi Messi claimed the Ballon d&#x27;Or as the world&#x27;s best...\n",
       "\n",
       "[2] Lionel Messi Net Worth: How the Soccer Star Makes and Spends ... - Insider\n",
       "CHANDAN KHANNA/Getty Images Messi took home a mind-boggling $65 million in on-field earnings over the last year — more than all but one soccer player on the planet. His Inter Miami salary alone is worth $20,446,667 annually, per AP News, which means he earns roughly $393,000 per week or $56,000 per day from the Major League Soccer club.\n",
       "\n",
       "[3] Lionel Messi Net Worth\n",
       "$600 Million Salary: $75 Million Date of Birth: Jun 24, 1987 (36 years old) Place of Birth: Rosario, Argentina Gender: Male Height: 5 ft 6 in (1.69 m) Profession: Football player Nationality:...\n",
       "\n",
       "Thought: Snippet 1 says $130M, but it may be referring to other athletes based on the rest of the snippet.\n",
       "Snippets 2 and 3 talk about his salary (with contradictory numbers), but not his net worth. Thus, there are no relevant quotes here, and I should make another search.\n",
       "I will make the search narrower using quotes.\n",
       "Act: search(messi &quot;net worth&quot;)\n",
       "Observation:\n",
       "[1] Lionel Messi - Forbes\n",
       "About Lionel Messi. Messi claimed the Ballon d&#x27;Or as the world&#x27;s best soccer player for a record seventh time in 2021, putting him two ahead of his rival Cristiano Ronaldo. He transferred to Paris ...\n",
       "\n",
       "[2] Lionel Messi Net Worth: How the Soccer Star Makes and Spends ... - Insider\n",
       "His net worth is an eye-watering $600 million. Leo Messi of Paris Saint-Germain looks on during warmup before the Ligue 1 Uber Eats match between Paris Saint Germain and ESTAC Troyes at Parc des Princes on May 08, 2022 in Paris, France. Photo by Aurelien Meunier - PSG/PSG via Getty Images That&#x27;s according to Celebrity Net Worth. Advertisement\n",
       "\n",
       "[3] Lionel Messi&amp;#39;s new $650,000 Bentley shows of his massive net worth\n",
       "In 2023, Messi&#x27;s net worth is a staggering $620 million, securing his place as the third-highest-paid athlete globally. A recent addition to Messi&#x27;s extravagant lifestyle is a sleek Bentley...\n",
       "\n",
       "Thought: Snippets 2 and 3 list his net worth.\n",
       "Act: extract_quotes()\n",
       "Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet 2: &quot;His net worth is an eye-watering $600 million&quot;\n",
       "- Snippet 3: &quot;In 2023, Messi&#x27;s net worth is a staggering $620 million&quot;\n",
       "Thought: I have all the information I need to respond, so I&#x27;ll list the quotes and then respond.\n",
       "Act: list_quotes()\n",
       "Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Query: Ronaldinho Gaucho net worth\n",
       "- Snippet 1: &quot;Ronaldinho’s net worth is estimated to be roughly $90 Million&quot;\n",
       "- Snippet 2: &quot;Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million.&quot;\n",
       "- Snippet 3: &quot;Ronaldinho has an outstanding net worth of $90 million&quot;\n",
       "Query: messi &quot;net worth&quot;\n",
       "- Snippet 2: &quot;His net worth is an eye-watering $600 million&quot;\n",
       "- Snippet 3: &quot;In 2023, Messi&#x27;s net worth is a staggering $620 million&quot;\n",
       "Thought: I will write a response now.\n",
       "Act: respond(Messi has an estimated net worth between $600 and $620 million, while Ronaldinho has an estimated net worth of $90 million. Thus, Messi is richer)\n",
       "</div></div></div></pre>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Pre-load the prompt and system message so we can reuse this\n",
    "search_lm = llama2 + init_system()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's try a few prompts:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style='margin: 0px; padding: 0px; padding-left: 8px; margin-left: -8px; border-radius: 0px; border-left: 1px solid rgba(127, 127, 127, 0.2); white-space: pre-wrap; font-family: ColfaxAI, Arial; font-size: 15px; line-height: 23px;'><div style='display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;'><div style='flex: 0 0 80px; opacity: 0.5;'>system</div><div style='flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;'><div style='display: inline-block; cursor: pointer; opacity: 0.5; width: 2px; margin-left: -2px;' onClick='this.nextSibling.style.display = \"inline\"; this.style.display = \"none\"'>&caron;</div><div style='display: none;'>You are a nice chatbot that answers users&#x27; queries. Whenever you get a question, you run a loop of [Thought, Act, Observation] until you hit a response, where Act is one of (search, respond, extract_quotes, list_quotes).\n",
       "You have a storehouse of facts, but you *always* search if you need information that depends on current events, since what you know may be out-of-date.\n",
       "After searching, if you find information in the snippets, you should extract quotes.\n",
       "If you need, you can make multiple searches.\n",
       "You should only ask the user for more information is their question is ambiguous.\n",
       "If the snippets are ambiguous or don&#x27;t contain enough information, you should make additional searches instead of asking the user.\n",
       "Here are some example interactions:\n",
       "---\n",
       "User: Who is the current president of the US?\n",
       "Thought: Since the president may have changed, my information may be out of date. Thus, I need to search the web for this.\n",
       "Act: search(current US president)\n",
       "Observation: \n",
       "[1] Joe Biden: The President | The White House\n",
       "Joe Biden The President House — with thousands of train rides in between Download Official Portrait President Biden represented Delaware for 36 years in the U.S. Senate before becoming the...\n",
       "\n",
       "[2] President of the United States - Wikipedia\n",
       "The president of the United States ( POTUS) [A] is the head of state and head of government of the United States. The president directs the executive branch of the federal government and is the commander-in-chief of the United States Armed Forces . The power of the presidency has grown substantially [11] since the first president, George ...\n",
       "\n",
       "[3] List of presidents of the United States - Wikipedia\n",
       "Grover Cleveland served two non-consecutive terms and is therefore counted as the 22nd and 24th president of the United States, giving rise to the discrepancy between the number of presidencies and the number of persons who have served as president. [5] The incumbent president is Joe Biden. [6]\n",
       "\n",
       "Thought: Snippets [1] and [3] clearly indicate that Joe Biden is the current president.\n",
       "Act: extract_quotes()\n",
       "Question: Who is the current president of the US?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet 1: &quot;Joe Biden: The President | White House&quot;\n",
       "- Snippet 3: &quot;The incumbent president is Joe Biden&quot;\n",
       "Thought: I have enough information to respond, so I will list the quotes and then respond.\n",
       "Act: list_quotes()\n",
       "Question: Who is the current president of the US?\n",
       "Query: current US president\n",
       "- Snippet 1: &quot;Joe Biden: The President | White House&quot;\n",
       "- Snippet 3: &quot;The incumbent president is Joe Biden&quot;\n",
       "Thought: I will write a response now.\n",
       "Act: respond(The current president of the US is Joe Biden)\n",
       "---\n",
       "User: What is the capital of France?\n",
       "Thought: It is really unlikely that the capital of France changed since my database was last updated. So, I don&#x27;t need to search the web, and can respond.\n",
       "Act: respond(The capital of France is Paris)\n",
       "---\n",
       "User: What is the capital of Georgia?\n",
       "Thought: The user can be asking about Georgia the country or Georgia the state. I should confirm which one before issuing a final response\n",
       "Act: respond(Do you mean the state or the country?)\n",
       "Observation:\n",
       "User: The state\n",
       "Thought: The capital of Georgia probably didn&#x27;t change since my database was last updated, so I can respond. \n",
       "Act: respond(The capital of Georgia is Atlanta)\n",
       "---\n",
       "User: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Thought: To answer this, I will need to search for each of their net worths, and then compare.\n",
       "Act: search(Ronaldinho Gaucho net worth)\n",
       "Observation:\n",
       "[1] Ronaldinho&amp;#39;s Net Worth (Updated 2023) | Wealthy Gorilla\n",
       "Introduction As of September 2023, Ronaldinho’s net worth is estimated to be roughly $90 Million. Ronaldo de Assis Moreira, better known as Ronaldinho, is a Brazilian former professional footballer and ambassador for Barcelona. from Porto Alegre. He is regarded to be one of the best football players of all time. Early Life\n",
       "\n",
       "[2] Ronaldinho Net Worth | Celebrity Net Worth\n",
       "Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million. Ronaldinho was once considered to be the best soccer player in the world. He was twice the...\n",
       "\n",
       "[3] Ronaldinho Net Worth: 2022, Career, House, Cars &amp;amp; Lifestyle - Players Bio\n",
       "A Brazilian legend, Ronaldinho has an outstanding net worth of $90 million. Even at his time, this sum was as impressive as it is now. Ronaldinho is $90 million rich because of football. But let me stop you right there. It’s not in everybody’s forte to excel as the Brazilian did.\n",
       "\n",
       "Thought: All snippets seem to talk about his net worth.\n",
       "Act: extract_quotes()\n",
       "Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet 1: &quot;Ronaldinho’s net worth is estimated to be roughly $90 Million&quot;\n",
       "- Snippet 2: &quot;Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million.&quot;\n",
       "- Snippet 3: &quot;Ronaldinho has an outstanding net worth of $90 million&quot;\n",
       "Thought: I still need to search for Messi&#x27;s net worth and compare\n",
       "Act: search(messi net worth)\n",
       "Observation:\n",
       "[1] Lionel Messi - Forbes\n",
       "$130M 2023 The World&#x27;s Highest-Paid Athletes Earnings as of 5/16/23 Photo by Antonio Borga/Eurasia Sport Images/Getty Images About Lionel Messi Messi claimed the Ballon d&#x27;Or as the world&#x27;s best...\n",
       "\n",
       "[2] Lionel Messi Net Worth: How the Soccer Star Makes and Spends ... - Insider\n",
       "CHANDAN KHANNA/Getty Images Messi took home a mind-boggling $65 million in on-field earnings over the last year — more than all but one soccer player on the planet. His Inter Miami salary alone is worth $20,446,667 annually, per AP News, which means he earns roughly $393,000 per week or $56,000 per day from the Major League Soccer club.\n",
       "\n",
       "[3] Lionel Messi Net Worth\n",
       "$600 Million Salary: $75 Million Date of Birth: Jun 24, 1987 (36 years old) Place of Birth: Rosario, Argentina Gender: Male Height: 5 ft 6 in (1.69 m) Profession: Football player Nationality:...\n",
       "\n",
       "Thought: Snippet 1 says $130M, but it may be referring to other athletes based on the rest of the snippet.\n",
       "Snippets 2 and 3 talk about his salary (with contradictory numbers), but not his net worth. Thus, there are no relevant quotes here, and I should make another search.\n",
       "I will make the search narrower using quotes.\n",
       "Act: search(messi &quot;net worth&quot;)\n",
       "Observation:\n",
       "[1] Lionel Messi - Forbes\n",
       "About Lionel Messi. Messi claimed the Ballon d&#x27;Or as the world&#x27;s best soccer player for a record seventh time in 2021, putting him two ahead of his rival Cristiano Ronaldo. He transferred to Paris ...\n",
       "\n",
       "[2] Lionel Messi Net Worth: How the Soccer Star Makes and Spends ... - Insider\n",
       "His net worth is an eye-watering $600 million. Leo Messi of Paris Saint-Germain looks on during warmup before the Ligue 1 Uber Eats match between Paris Saint Germain and ESTAC Troyes at Parc des Princes on May 08, 2022 in Paris, France. Photo by Aurelien Meunier - PSG/PSG via Getty Images That&#x27;s according to Celebrity Net Worth. Advertisement\n",
       "\n",
       "[3] Lionel Messi&amp;#39;s new $650,000 Bentley shows of his massive net worth\n",
       "In 2023, Messi&#x27;s net worth is a staggering $620 million, securing his place as the third-highest-paid athlete globally. A recent addition to Messi&#x27;s extravagant lifestyle is a sleek Bentley...\n",
       "\n",
       "Thought: Snippets 2 and 3 list his net worth.\n",
       "Act: extract_quotes()\n",
       "Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet 2: &quot;His net worth is an eye-watering $600 million&quot;\n",
       "- Snippet 3: &quot;In 2023, Messi&#x27;s net worth is a staggering $620 million&quot;\n",
       "Thought: I have all the information I need to respond, so I&#x27;ll list the quotes and then respond.\n",
       "Act: list_quotes()\n",
       "Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Query: Ronaldinho Gaucho net worth\n",
       "- Snippet 1: &quot;Ronaldinho’s net worth is estimated to be roughly $90 Million&quot;\n",
       "- Snippet 2: &quot;Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million.&quot;\n",
       "- Snippet 3: &quot;Ronaldinho has an outstanding net worth of $90 million&quot;\n",
       "Query: messi &quot;net worth&quot;\n",
       "- Snippet 2: &quot;His net worth is an eye-watering $600 million&quot;\n",
       "- Snippet 3: &quot;In 2023, Messi&#x27;s net worth is a staggering $620 million&quot;\n",
       "Thought: I will write a response now.\n",
       "Act: respond(Messi has an estimated net worth between $600 and $620 million, while Ronaldinho has an estimated net worth of $90 million. Thus, Messi is richer)\n",
       "</div></div></div><div style='display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;'><div style='flex: 0 0 80px; opacity: 0.5;'>user</div><div style='flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;'>User: Where does Sam Altman work?</div></div><div style='display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;'><div style='flex: 0 0 80px; opacity: 0.5;'>assistant</div><div style='flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;'>Thought:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> I</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> need</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> search</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> the</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> web</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> find</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> the</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> most</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> up</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>-</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>-</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>date</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> information</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>.</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>\n",
       "</span>Act:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> search</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>(</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>Sam</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Alt</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>man</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> work</span>)\n",
       "\n",
       "Observation:\n",
       "[1] A timeline of Sam Altman&amp;#39;s firing from OpenAI - TechCrunch\n",
       "In a dramatic turn of events late Friday, ex-Y Combinator president Sam Altman was fired as CEO of AI startup OpenAI, the company behind viral AI hits like , and , by OpenAI’s board of...\n",
       "\n",
       "[2] Sam Altman is back at OpenAI … with a guest badge - CNN\n",
       "New York CNN — Sam Altman is back at OpenAI. Well… he’s back at the OpenAI headquarters in San Francisco, anyway. Whether or not he returns as CEO of the ChatGPT parent company is still up in...\n",
       "\n",
       "[3] OpenAI CEO Sam Altman lands new job at Microsoft after surprise firing\n",
       "Sam Altman, the former CEO of OpenAI, is to start a new venture at Microsoft, just days after being fired by the company behind ChatGPT and DALL-E. Here&#x27;s a quick summary of the big shake-up in...\n",
       "\n",
       "Thought:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> All</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> sni</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ppets</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> seem</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> be</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> talking</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> about</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Sam</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Alt</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>man</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>&#x27;</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>s</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> departure</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> from</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Open</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>AI</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>.</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>\n",
       "</span>Act:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> extract</span>_quote<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>s</span>()\n",
       "Question: Where does Sam Altman work?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> </span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>1</span>:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> &quot;</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>Sam</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Alt</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>man</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> was</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> fired</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> as</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> CE</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>O</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> of</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> A</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>I</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> startup</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Open</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>AI</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>&quot;</span>\n",
       "<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>-</span> Snippet<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> </span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>2</span>:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> &quot;</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>Sam</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Alt</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>man</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> is</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> back</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> at</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Open</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>AI</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>&quot;</span>\n",
       "<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>-</span> Snippet<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> </span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>3</span>:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> &quot;</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>Sam</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Alt</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>man</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>,</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> the</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> former</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> CE</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>O</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> of</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Open</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>AI</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>,</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> is</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> start</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> a</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> new</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> vent</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ure</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> at</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Microsoft</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>&quot;</span>\n",
       "Thought:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> I</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> still</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> need</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> search</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> confirm</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> if</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> he</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> is</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> still</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> at</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Microsoft</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>.</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>\n",
       "</span>Act:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> search</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>(</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>Sam</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Alt</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>man</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Microsoft</span>)\n",
       "\n",
       "Observation:\n",
       "[1] Sam Altman joins Microsoft as OpenAI taps Emmett Shear for ... - CNN\n",
       "Sam Altman, who was ousted as CEO of OpenAI in a chaotic boardroom coup Friday, is joining Microsoft, the tech giant said Monday. Meanwhile, Emmett Shear, the former CEO of streaming service...\n",
       "\n",
       "[2] Ousted OpenAI leader Sam Altman joins Microsoft : NPR\n",
       "Sam Altman, who co-founded OpenAI, the influential maker of ChatGPT, will join Microsoft to help lead a new advanced artificial intelligence team. The surprise development follows Altman&#x27;s abrupt ...\n",
       "\n",
       "[3] Microsoft hires Sam Altman, new OpenAI CEO vows to investigate his ...\n",
       "Microsoft snapped up Sam Altman and another architect of OpenAI for a new venture after their sudden departures shocked the artificial intelligence world, leaving the newly installed CEO of...\n",
       "\n",
       "Thought:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> All</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> snippet</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> indicate</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> that</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Sam</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Alt</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>man</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> is</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> now</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> working</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> at</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Microsoft</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>.</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>\n",
       "</span>Act:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> respond</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>(</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>Sam</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Alt</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>man</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> currently</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> works</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> at</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Microsoft</span>)\n",
       "</div></div></pre>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "lm = search_lm + chat_search('Where does Sam Altman work?')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We didn't prompt the model with follow up questions, but let's give it a shot anyway:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style='margin: 0px; padding: 0px; padding-left: 8px; margin-left: -8px; border-radius: 0px; border-left: 1px solid rgba(127, 127, 127, 0.2); white-space: pre-wrap; font-family: ColfaxAI, Arial; font-size: 15px; line-height: 23px;'><div style='display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;'><div style='flex: 0 0 80px; opacity: 0.5;'>system</div><div style='flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;'><div style='display: inline-block; cursor: pointer; opacity: 0.5; width: 2px; margin-left: -2px;' onClick='this.nextSibling.style.display = \"inline\"; this.style.display = \"none\"'>&caron;</div><div style='display: none;'>You are a nice chatbot that answers users&#x27; queries. Whenever you get a question, you run a loop of [Thought, Act, Observation] until you hit a response, where Act is one of (search, respond, extract_quotes, list_quotes).\n",
       "You have a storehouse of facts, but you *always* search if you need information that depends on current events, since what you know may be out-of-date.\n",
       "After searching, if you find information in the snippets, you should extract quotes.\n",
       "If you need, you can make multiple searches.\n",
       "You should only ask the user for more information is their question is ambiguous.\n",
       "If the snippets are ambiguous or don&#x27;t contain enough information, you should make additional searches instead of asking the user.\n",
       "Here are some example interactions:\n",
       "---\n",
       "User: Who is the current president of the US?\n",
       "Thought: Since the president may have changed, my information may be out of date. Thus, I need to search the web for this.\n",
       "Act: search(current US president)\n",
       "Observation: \n",
       "[1] Joe Biden: The President | The White House\n",
       "Joe Biden The President House — with thousands of train rides in between Download Official Portrait President Biden represented Delaware for 36 years in the U.S. Senate before becoming the...\n",
       "\n",
       "[2] President of the United States - Wikipedia\n",
       "The president of the United States ( POTUS) [A] is the head of state and head of government of the United States. The president directs the executive branch of the federal government and is the commander-in-chief of the United States Armed Forces . The power of the presidency has grown substantially [11] since the first president, George ...\n",
       "\n",
       "[3] List of presidents of the United States - Wikipedia\n",
       "Grover Cleveland served two non-consecutive terms and is therefore counted as the 22nd and 24th president of the United States, giving rise to the discrepancy between the number of presidencies and the number of persons who have served as president. [5] The incumbent president is Joe Biden. [6]\n",
       "\n",
       "Thought: Snippets [1] and [3] clearly indicate that Joe Biden is the current president.\n",
       "Act: extract_quotes()\n",
       "Question: Who is the current president of the US?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet 1: &quot;Joe Biden: The President | White House&quot;\n",
       "- Snippet 3: &quot;The incumbent president is Joe Biden&quot;\n",
       "Thought: I have enough information to respond, so I will list the quotes and then respond.\n",
       "Act: list_quotes()\n",
       "Question: Who is the current president of the US?\n",
       "Query: current US president\n",
       "- Snippet 1: &quot;Joe Biden: The President | White House&quot;\n",
       "- Snippet 3: &quot;The incumbent president is Joe Biden&quot;\n",
       "Thought: I will write a response now.\n",
       "Act: respond(The current president of the US is Joe Biden)\n",
       "---\n",
       "User: What is the capital of France?\n",
       "Thought: It is really unlikely that the capital of France changed since my database was last updated. So, I don&#x27;t need to search the web, and can respond.\n",
       "Act: respond(The capital of France is Paris)\n",
       "---\n",
       "User: What is the capital of Georgia?\n",
       "Thought: The user can be asking about Georgia the country or Georgia the state. I should confirm which one before issuing a final response\n",
       "Act: respond(Do you mean the state or the country?)\n",
       "Observation:\n",
       "User: The state\n",
       "Thought: The capital of Georgia probably didn&#x27;t change since my database was last updated, so I can respond. \n",
       "Act: respond(The capital of Georgia is Atlanta)\n",
       "---\n",
       "User: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Thought: To answer this, I will need to search for each of their net worths, and then compare.\n",
       "Act: search(Ronaldinho Gaucho net worth)\n",
       "Observation:\n",
       "[1] Ronaldinho&amp;#39;s Net Worth (Updated 2023) | Wealthy Gorilla\n",
       "Introduction As of September 2023, Ronaldinho’s net worth is estimated to be roughly $90 Million. Ronaldo de Assis Moreira, better known as Ronaldinho, is a Brazilian former professional footballer and ambassador for Barcelona. from Porto Alegre. He is regarded to be one of the best football players of all time. Early Life\n",
       "\n",
       "[2] Ronaldinho Net Worth | Celebrity Net Worth\n",
       "Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million. Ronaldinho was once considered to be the best soccer player in the world. He was twice the...\n",
       "\n",
       "[3] Ronaldinho Net Worth: 2022, Career, House, Cars &amp;amp; Lifestyle - Players Bio\n",
       "A Brazilian legend, Ronaldinho has an outstanding net worth of $90 million. Even at his time, this sum was as impressive as it is now. Ronaldinho is $90 million rich because of football. But let me stop you right there. It’s not in everybody’s forte to excel as the Brazilian did.\n",
       "\n",
       "Thought: All snippets seem to talk about his net worth.\n",
       "Act: extract_quotes()\n",
       "Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet 1: &quot;Ronaldinho’s net worth is estimated to be roughly $90 Million&quot;\n",
       "- Snippet 2: &quot;Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million.&quot;\n",
       "- Snippet 3: &quot;Ronaldinho has an outstanding net worth of $90 million&quot;\n",
       "Thought: I still need to search for Messi&#x27;s net worth and compare\n",
       "Act: search(messi net worth)\n",
       "Observation:\n",
       "[1] Lionel Messi - Forbes\n",
       "$130M 2023 The World&#x27;s Highest-Paid Athletes Earnings as of 5/16/23 Photo by Antonio Borga/Eurasia Sport Images/Getty Images About Lionel Messi Messi claimed the Ballon d&#x27;Or as the world&#x27;s best...\n",
       "\n",
       "[2] Lionel Messi Net Worth: How the Soccer Star Makes and Spends ... - Insider\n",
       "CHANDAN KHANNA/Getty Images Messi took home a mind-boggling $65 million in on-field earnings over the last year — more than all but one soccer player on the planet. His Inter Miami salary alone is worth $20,446,667 annually, per AP News, which means he earns roughly $393,000 per week or $56,000 per day from the Major League Soccer club.\n",
       "\n",
       "[3] Lionel Messi Net Worth\n",
       "$600 Million Salary: $75 Million Date of Birth: Jun 24, 1987 (36 years old) Place of Birth: Rosario, Argentina Gender: Male Height: 5 ft 6 in (1.69 m) Profession: Football player Nationality:...\n",
       "\n",
       "Thought: Snippet 1 says $130M, but it may be referring to other athletes based on the rest of the snippet.\n",
       "Snippets 2 and 3 talk about his salary (with contradictory numbers), but not his net worth. Thus, there are no relevant quotes here, and I should make another search.\n",
       "I will make the search narrower using quotes.\n",
       "Act: search(messi &quot;net worth&quot;)\n",
       "Observation:\n",
       "[1] Lionel Messi - Forbes\n",
       "About Lionel Messi. Messi claimed the Ballon d&#x27;Or as the world&#x27;s best soccer player for a record seventh time in 2021, putting him two ahead of his rival Cristiano Ronaldo. He transferred to Paris ...\n",
       "\n",
       "[2] Lionel Messi Net Worth: How the Soccer Star Makes and Spends ... - Insider\n",
       "His net worth is an eye-watering $600 million. Leo Messi of Paris Saint-Germain looks on during warmup before the Ligue 1 Uber Eats match between Paris Saint Germain and ESTAC Troyes at Parc des Princes on May 08, 2022 in Paris, France. Photo by Aurelien Meunier - PSG/PSG via Getty Images That&#x27;s according to Celebrity Net Worth. Advertisement\n",
       "\n",
       "[3] Lionel Messi&amp;#39;s new $650,000 Bentley shows of his massive net worth\n",
       "In 2023, Messi&#x27;s net worth is a staggering $620 million, securing his place as the third-highest-paid athlete globally. A recent addition to Messi&#x27;s extravagant lifestyle is a sleek Bentley...\n",
       "\n",
       "Thought: Snippets 2 and 3 list his net worth.\n",
       "Act: extract_quotes()\n",
       "Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet 2: &quot;His net worth is an eye-watering $600 million&quot;\n",
       "- Snippet 3: &quot;In 2023, Messi&#x27;s net worth is a staggering $620 million&quot;\n",
       "Thought: I have all the information I need to respond, so I&#x27;ll list the quotes and then respond.\n",
       "Act: list_quotes()\n",
       "Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Query: Ronaldinho Gaucho net worth\n",
       "- Snippet 1: &quot;Ronaldinho’s net worth is estimated to be roughly $90 Million&quot;\n",
       "- Snippet 2: &quot;Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million.&quot;\n",
       "- Snippet 3: &quot;Ronaldinho has an outstanding net worth of $90 million&quot;\n",
       "Query: messi &quot;net worth&quot;\n",
       "- Snippet 2: &quot;His net worth is an eye-watering $600 million&quot;\n",
       "- Snippet 3: &quot;In 2023, Messi&#x27;s net worth is a staggering $620 million&quot;\n",
       "Thought: I will write a response now.\n",
       "Act: respond(Messi has an estimated net worth between $600 and $620 million, while Ronaldinho has an estimated net worth of $90 million. Thus, Messi is richer)\n",
       "</div></div></div><div style='display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;'><div style='flex: 0 0 80px; opacity: 0.5;'>user</div><div style='flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;'>User: Where does Sam Altman work?</div></div><div style='display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;'><div style='flex: 0 0 80px; opacity: 0.5;'>assistant</div><div style='flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;'>Thought:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> I</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> need</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> search</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> the</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> web</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> find</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> the</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> most</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> up</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>-</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>-</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>date</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> information</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>.</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>\n",
       "</span>Act:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> search</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>(</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>Sam</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Alt</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>man</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> work</span>)\n",
       "\n",
       "Observation:\n",
       "[1] A timeline of Sam Altman&amp;#39;s firing from OpenAI - TechCrunch\n",
       "In a dramatic turn of events late Friday, ex-Y Combinator president Sam Altman was fired as CEO of AI startup OpenAI, the company behind viral AI hits like , and , by OpenAI’s board of...\n",
       "\n",
       "[2] Sam Altman is back at OpenAI … with a guest badge - CNN\n",
       "New York CNN — Sam Altman is back at OpenAI. Well… he’s back at the OpenAI headquarters in San Francisco, anyway. Whether or not he returns as CEO of the ChatGPT parent company is still up in...\n",
       "\n",
       "[3] OpenAI CEO Sam Altman lands new job at Microsoft after surprise firing\n",
       "Sam Altman, the former CEO of OpenAI, is to start a new venture at Microsoft, just days after being fired by the company behind ChatGPT and DALL-E. Here&#x27;s a quick summary of the big shake-up in...\n",
       "\n",
       "Thought:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> All</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> sni</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ppets</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> seem</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> be</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> talking</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> about</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Sam</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Alt</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>man</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>&#x27;</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>s</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> departure</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> from</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Open</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>AI</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>.</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>\n",
       "</span>Act:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> extract</span>_quote<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>s</span>()\n",
       "Question: Where does Sam Altman work?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> </span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>1</span>:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> &quot;</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>Sam</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Alt</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>man</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> was</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> fired</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> as</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> CE</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>O</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> of</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> A</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>I</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> startup</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Open</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>AI</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>&quot;</span>\n",
       "<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>-</span> Snippet<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> </span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>2</span>:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> &quot;</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>Sam</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Alt</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>man</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> is</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> back</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> at</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Open</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>AI</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>&quot;</span>\n",
       "<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>-</span> Snippet<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> </span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>3</span>:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> &quot;</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>Sam</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Alt</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>man</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>,</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> the</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> former</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> CE</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>O</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> of</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Open</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>AI</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>,</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> is</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> start</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> a</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> new</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> vent</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ure</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> at</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Microsoft</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>&quot;</span>\n",
       "Thought:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> I</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> still</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> need</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> search</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> confirm</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> if</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> he</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> is</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> still</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> at</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Microsoft</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>.</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>\n",
       "</span>Act:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> search</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>(</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>Sam</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Alt</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>man</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Microsoft</span>)\n",
       "\n",
       "Observation:\n",
       "[1] Sam Altman joins Microsoft as OpenAI taps Emmett Shear for ... - CNN\n",
       "Sam Altman, who was ousted as CEO of OpenAI in a chaotic boardroom coup Friday, is joining Microsoft, the tech giant said Monday. Meanwhile, Emmett Shear, the former CEO of streaming service...\n",
       "\n",
       "[2] Ousted OpenAI leader Sam Altman joins Microsoft : NPR\n",
       "Sam Altman, who co-founded OpenAI, the influential maker of ChatGPT, will join Microsoft to help lead a new advanced artificial intelligence team. The surprise development follows Altman&#x27;s abrupt ...\n",
       "\n",
       "[3] Microsoft hires Sam Altman, new OpenAI CEO vows to investigate his ...\n",
       "Microsoft snapped up Sam Altman and another architect of OpenAI for a new venture after their sudden departures shocked the artificial intelligence world, leaving the newly installed CEO of...\n",
       "\n",
       "Thought:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> All</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> snippet</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> indicate</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> that</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Sam</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Alt</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>man</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> is</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> now</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> working</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> at</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Microsoft</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>.</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>\n",
       "</span>Act:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> respond</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>(</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>Sam</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Alt</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>man</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> currently</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> works</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> at</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Microsoft</span>)\n",
       "</div></div><div style='display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;'><div style='flex: 0 0 80px; opacity: 0.5;'>user</div><div style='flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;'>User: Why did he leave OpenAI?</div></div><div style='display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;'><div style='flex: 0 0 80px; opacity: 0.5;'>assistant</div><div style='flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;'>Thought:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> I</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> need</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> search</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> the</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> web</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> find</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> the</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> most</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> up</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>-</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>-</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>date</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> information</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>.</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>\n",
       "</span>Act:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> search</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>(</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>Sam</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Alt</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>man</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Open</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>AI</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> departure</span>)\n",
       "\n",
       "Observation:\n",
       "[1] Sam Altman Departs OpenAI | TIME\n",
       "Sam Altman Departs OpenAI After Board Loses Confidence in Him. ... The sudden departure comes as a shock to the tech world. Altman was an OpenAI founding co-chair in 2015 along with Elon Musk.\n",
       "\n",
       "[2] OpenAI announces leadership transition\n",
       "November 17, 2023 Authors OpenAI Announcements Chief technology officer Mira Murati appointed interim CEO to lead OpenAI; Sam Altman departs the company. Search process underway to identify permanent successor.\n",
       "\n",
       "[3] ChatGPT parent company OpenAI fires CEO Sam Altman - CNN\n",
       "OpenAI, the organization behind the viral chatbot ChatGPT, announced on Friday its CEO and founder, Sam Altman, was fired and will be departing the company, effective immediately. The...\n",
       "\n",
       "Thought:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> All</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> snippet</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> indicate</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> that</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Sam</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Alt</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>man</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> was</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> fired</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> from</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Open</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>AI</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>.</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>\n",
       "</span>Act:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> extract</span>_quote<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>s</span>()\n",
       "Question: Why did he leave OpenAI?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> </span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>1</span>:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> &quot;</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>Sam</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Alt</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>man</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Depart</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>s</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Open</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>AI</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> After</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Board</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Los</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>es</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Conf</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>idence</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> in</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Him</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>&quot;</span>\n",
       "<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>-</span> Snippet<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> </span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>2</span>:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> &quot;</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>Open</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>AI</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> announ</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ces</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> leadership</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> transition</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>&quot;</span>\n",
       "<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>-</span> Snippet<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> </span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>3</span>:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> &quot;</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>Ch</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>at</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>GP</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>&quot;</span>\n",
       "Thought:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> I</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> have</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> enough</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> information</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> respond</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>,</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> so</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> I</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> will</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> list</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> the</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> quotes</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> and</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> then</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> respond</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>.</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>\n",
       "</span>Act:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> list</span>_quote<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>s</span>()\n",
       "Question: Why did he leave OpenAI?\n",
       "Query: Sam Altman work\n",
       "- Snippet 1: &quot;Sam Altman was fired as CEO of AI startup OpenAI&quot;\n",
       "- Snippet 2: &quot;Sam Altman is back at OpenAI&quot;\n",
       "- Snippet 3: &quot;Sam Altman, the former CEO of OpenAI, is to start a new venture at Microsoft&quot;\n",
       "Query: Sam Altman OpenAI departure\n",
       "- Snippet 1: &quot;Sam Altman Departs OpenAI After Board Loses Confidence in Him&quot;\n",
       "- Snippet 2: &quot;OpenAI announces leadership transition&quot;\n",
       "- Snippet 3: &quot;ChatGP&quot;\n",
       "Thought:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> I</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> will</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> write</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> a</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> response</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> now</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>.</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>\n",
       "</span>Act:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> respond</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>(</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>Sam</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Alt</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>man</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> was</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> fired</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> from</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Open</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>AI</span>)\n",
       "</div></div></pre>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "lm += chat_search('Why did he leave OpenAI?')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's try a few other questions:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style='margin: 0px; padding: 0px; padding-left: 8px; margin-left: -8px; border-radius: 0px; border-left: 1px solid rgba(127, 127, 127, 0.2); white-space: pre-wrap; font-family: ColfaxAI, Arial; font-size: 15px; line-height: 23px;'><div style='display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;'><div style='flex: 0 0 80px; opacity: 0.5;'>system</div><div style='flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;'><div style='display: inline-block; cursor: pointer; opacity: 0.5; width: 2px; margin-left: -2px;' onClick='this.nextSibling.style.display = \"inline\"; this.style.display = \"none\"'>&caron;</div><div style='display: none;'>You are a nice chatbot that answers users&#x27; queries. Whenever you get a question, you run a loop of [Thought, Act, Observation] until you hit a response, where Act is one of (search, respond, extract_quotes, list_quotes).\n",
       "You have a storehouse of facts, but you *always* search if you need information that depends on current events, since what you know may be out-of-date.\n",
       "After searching, if you find information in the snippets, you should extract quotes.\n",
       "If you need, you can make multiple searches.\n",
       "You should only ask the user for more information is their question is ambiguous.\n",
       "If the snippets are ambiguous or don&#x27;t contain enough information, you should make additional searches instead of asking the user.\n",
       "Here are some example interactions:\n",
       "---\n",
       "User: Who is the current president of the US?\n",
       "Thought: Since the president may have changed, my information may be out of date. Thus, I need to search the web for this.\n",
       "Act: search(current US president)\n",
       "Observation: \n",
       "[1] Joe Biden: The President | The White House\n",
       "Joe Biden The President House — with thousands of train rides in between Download Official Portrait President Biden represented Delaware for 36 years in the U.S. Senate before becoming the...\n",
       "\n",
       "[2] President of the United States - Wikipedia\n",
       "The president of the United States ( POTUS) [A] is the head of state and head of government of the United States. The president directs the executive branch of the federal government and is the commander-in-chief of the United States Armed Forces . The power of the presidency has grown substantially [11] since the first president, George ...\n",
       "\n",
       "[3] List of presidents of the United States - Wikipedia\n",
       "Grover Cleveland served two non-consecutive terms and is therefore counted as the 22nd and 24th president of the United States, giving rise to the discrepancy between the number of presidencies and the number of persons who have served as president. [5] The incumbent president is Joe Biden. [6]\n",
       "\n",
       "Thought: Snippets [1] and [3] clearly indicate that Joe Biden is the current president.\n",
       "Act: extract_quotes()\n",
       "Question: Who is the current president of the US?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet 1: &quot;Joe Biden: The President | White House&quot;\n",
       "- Snippet 3: &quot;The incumbent president is Joe Biden&quot;\n",
       "Thought: I have enough information to respond, so I will list the quotes and then respond.\n",
       "Act: list_quotes()\n",
       "Question: Who is the current president of the US?\n",
       "Query: current US president\n",
       "- Snippet 1: &quot;Joe Biden: The President | White House&quot;\n",
       "- Snippet 3: &quot;The incumbent president is Joe Biden&quot;\n",
       "Thought: I will write a response now.\n",
       "Act: respond(The current president of the US is Joe Biden)\n",
       "---\n",
       "User: What is the capital of France?\n",
       "Thought: It is really unlikely that the capital of France changed since my database was last updated. So, I don&#x27;t need to search the web, and can respond.\n",
       "Act: respond(The capital of France is Paris)\n",
       "---\n",
       "User: What is the capital of Georgia?\n",
       "Thought: The user can be asking about Georgia the country or Georgia the state. I should confirm which one before issuing a final response\n",
       "Act: respond(Do you mean the state or the country?)\n",
       "Observation:\n",
       "User: The state\n",
       "Thought: The capital of Georgia probably didn&#x27;t change since my database was last updated, so I can respond. \n",
       "Act: respond(The capital of Georgia is Atlanta)\n",
       "---\n",
       "User: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Thought: To answer this, I will need to search for each of their net worths, and then compare.\n",
       "Act: search(Ronaldinho Gaucho net worth)\n",
       "Observation:\n",
       "[1] Ronaldinho&amp;#39;s Net Worth (Updated 2023) | Wealthy Gorilla\n",
       "Introduction As of September 2023, Ronaldinho’s net worth is estimated to be roughly $90 Million. Ronaldo de Assis Moreira, better known as Ronaldinho, is a Brazilian former professional footballer and ambassador for Barcelona. from Porto Alegre. He is regarded to be one of the best football players of all time. Early Life\n",
       "\n",
       "[2] Ronaldinho Net Worth | Celebrity Net Worth\n",
       "Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million. Ronaldinho was once considered to be the best soccer player in the world. He was twice the...\n",
       "\n",
       "[3] Ronaldinho Net Worth: 2022, Career, House, Cars &amp;amp; Lifestyle - Players Bio\n",
       "A Brazilian legend, Ronaldinho has an outstanding net worth of $90 million. Even at his time, this sum was as impressive as it is now. Ronaldinho is $90 million rich because of football. But let me stop you right there. It’s not in everybody’s forte to excel as the Brazilian did.\n",
       "\n",
       "Thought: All snippets seem to talk about his net worth.\n",
       "Act: extract_quotes()\n",
       "Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet 1: &quot;Ronaldinho’s net worth is estimated to be roughly $90 Million&quot;\n",
       "- Snippet 2: &quot;Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million.&quot;\n",
       "- Snippet 3: &quot;Ronaldinho has an outstanding net worth of $90 million&quot;\n",
       "Thought: I still need to search for Messi&#x27;s net worth and compare\n",
       "Act: search(messi net worth)\n",
       "Observation:\n",
       "[1] Lionel Messi - Forbes\n",
       "$130M 2023 The World&#x27;s Highest-Paid Athletes Earnings as of 5/16/23 Photo by Antonio Borga/Eurasia Sport Images/Getty Images About Lionel Messi Messi claimed the Ballon d&#x27;Or as the world&#x27;s best...\n",
       "\n",
       "[2] Lionel Messi Net Worth: How the Soccer Star Makes and Spends ... - Insider\n",
       "CHANDAN KHANNA/Getty Images Messi took home a mind-boggling $65 million in on-field earnings over the last year — more than all but one soccer player on the planet. His Inter Miami salary alone is worth $20,446,667 annually, per AP News, which means he earns roughly $393,000 per week or $56,000 per day from the Major League Soccer club.\n",
       "\n",
       "[3] Lionel Messi Net Worth\n",
       "$600 Million Salary: $75 Million Date of Birth: Jun 24, 1987 (36 years old) Place of Birth: Rosario, Argentina Gender: Male Height: 5 ft 6 in (1.69 m) Profession: Football player Nationality:...\n",
       "\n",
       "Thought: Snippet 1 says $130M, but it may be referring to other athletes based on the rest of the snippet.\n",
       "Snippets 2 and 3 talk about his salary (with contradictory numbers), but not his net worth. Thus, there are no relevant quotes here, and I should make another search.\n",
       "I will make the search narrower using quotes.\n",
       "Act: search(messi &quot;net worth&quot;)\n",
       "Observation:\n",
       "[1] Lionel Messi - Forbes\n",
       "About Lionel Messi. Messi claimed the Ballon d&#x27;Or as the world&#x27;s best soccer player for a record seventh time in 2021, putting him two ahead of his rival Cristiano Ronaldo. He transferred to Paris ...\n",
       "\n",
       "[2] Lionel Messi Net Worth: How the Soccer Star Makes and Spends ... - Insider\n",
       "His net worth is an eye-watering $600 million. Leo Messi of Paris Saint-Germain looks on during warmup before the Ligue 1 Uber Eats match between Paris Saint Germain and ESTAC Troyes at Parc des Princes on May 08, 2022 in Paris, France. Photo by Aurelien Meunier - PSG/PSG via Getty Images That&#x27;s according to Celebrity Net Worth. Advertisement\n",
       "\n",
       "[3] Lionel Messi&amp;#39;s new $650,000 Bentley shows of his massive net worth\n",
       "In 2023, Messi&#x27;s net worth is a staggering $620 million, securing his place as the third-highest-paid athlete globally. A recent addition to Messi&#x27;s extravagant lifestyle is a sleek Bentley...\n",
       "\n",
       "Thought: Snippets 2 and 3 list his net worth.\n",
       "Act: extract_quotes()\n",
       "Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet 2: &quot;His net worth is an eye-watering $600 million&quot;\n",
       "- Snippet 3: &quot;In 2023, Messi&#x27;s net worth is a staggering $620 million&quot;\n",
       "Thought: I have all the information I need to respond, so I&#x27;ll list the quotes and then respond.\n",
       "Act: list_quotes()\n",
       "Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Query: Ronaldinho Gaucho net worth\n",
       "- Snippet 1: &quot;Ronaldinho’s net worth is estimated to be roughly $90 Million&quot;\n",
       "- Snippet 2: &quot;Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million.&quot;\n",
       "- Snippet 3: &quot;Ronaldinho has an outstanding net worth of $90 million&quot;\n",
       "Query: messi &quot;net worth&quot;\n",
       "- Snippet 2: &quot;His net worth is an eye-watering $600 million&quot;\n",
       "- Snippet 3: &quot;In 2023, Messi&#x27;s net worth is a staggering $620 million&quot;\n",
       "Thought: I will write a response now.\n",
       "Act: respond(Messi has an estimated net worth between $600 and $620 million, while Ronaldinho has an estimated net worth of $90 million. Thus, Messi is richer)\n",
       "</div></div></div><div style='display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;'><div style='flex: 0 0 80px; opacity: 0.5;'>user</div><div style='flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;'>User: What new discoveries from the James Webb Space Telescope can I tell my 9 year old about?</div></div><div style='display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;'><div style='flex: 0 0 80px; opacity: 0.5;'>assistant</div><div style='flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;'>Thought:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> The</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> James</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Web</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>b</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Space</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> T</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>eles</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>cope</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> (</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>J</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>W</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ST</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>)</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> is</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> a</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> relatively</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> new</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> space</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> observ</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>atory</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>,</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> and</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> as</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> such</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>,</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> there</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> may</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> not</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> be</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> many</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> new</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> discover</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ies</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> available</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> yet</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>.</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> However</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>,</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> I</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> can</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> still</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> try</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> find</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> some</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> information</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> about</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> its</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> current</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> discover</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ies</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>.</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>\n",
       "</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>\n",
       "</span>Act:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> search</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>(</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>j</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>w</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>st</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> discover</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ies</span>)\n",
       "\n",
       "Observation:\n",
       "[1] 12 amazing James Webb Space Telescope discoveries across the universe\n",
       "The James Webb Space Telescope (Webb or JWST) is a pathfinder of scientific discovery, generating incredible insights about galaxies, planets, stars and all sorts of interesting cosmic objects ...\n",
       "\n",
       "[2] James Webb Space Telescope - NASA Science\n",
       "The James Webb Space Telescope is a giant leap forward in our quest to understand the Universe and our origins. Webb is examining every phase of cosmic history: from the first luminous glows after the Big Bang to the formation of galaxies, stars, and planets to the evolution of our own solar system. Learn about the 4 main science themes for ...\n",
       "\n",
       "[3] James Webb telescope discovers &amp;#39;Cosmic Vine&amp;#39; of 20 connected galaxies ...\n",
       "The James Webb Space Telescope has discovered a massive chain of 20 galaxies in the early universe, raising questions about the formation of the largest structures in the cosmos.\n",
       "\n",
       "Thought:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> The</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> sni</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ppets</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> mention</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> several</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> discover</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ies</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> made</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> by</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> the</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> J</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>W</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ST</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>,</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> but</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> they</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> do</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> not</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> seem</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> be</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> specifically</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> aim</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ed</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> at</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> a</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> </span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>9</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>-</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>year</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>-</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>old</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> audience</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>.</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>\n",
       "</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>\n",
       "</span>Act:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> extract</span>_quote<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>s</span>()\n",
       "Question: What new discoveries from the James Webb Space Telescope can I tell my 9 year old about?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> </span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>1</span>:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> &quot;</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>1</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>2</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> amaz</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ing</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> James</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Web</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>b</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Space</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Tele</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>scope</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> discover</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ies</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> across</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> the</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> universe</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>&quot;</span>\n",
       "<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>-</span> Snippet<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> </span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>2</span>:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> &quot;</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>The</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> James</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Web</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>b</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Space</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Tele</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>scope</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> is</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> a</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> giant</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> le</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ap</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> forward</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> in</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> our</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> quest</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> understand</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> the</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Un</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>iverse</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> and</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> our</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> origin</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>&quot;</span>\n",
       "<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>-</span> Snippet<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> </span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>3</span>:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> &quot;</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>The</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> James</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Web</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>b</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Space</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Tele</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>scope</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> has</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> discovered</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> a</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> massive</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> chain</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> of</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> </span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>2</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>0</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> galaxies</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> in</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> the</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> early</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> universe</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>&quot;</span>\n",
       "Thought:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> I</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> have</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> enough</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> information</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> respond</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>,</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> so</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> I</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> will</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> list</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> the</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> quotes</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> and</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> then</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> respond</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>.</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>\n",
       "</span>Act:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> list</span>_quote<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>s</span>()\n",
       "Question: What new discoveries from the James Webb Space Telescope can I tell my 9 year old about?\n",
       "Query: jwst discoveries\n",
       "- Snippet 1: &quot;12 amazing James Webb Space Telescope discoveries across the universe&quot;\n",
       "- Snippet 2: &quot;The James Webb Space Telescope is a giant leap forward in our quest to understand the Universe and our origin&quot;\n",
       "- Snippet 3: &quot;The James Webb Space Telescope has discovered a massive chain of 20 galaxies in the early universe&quot;\n",
       "Thought:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> I</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> will</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> write</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> a</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> response</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> now</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>.</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>\n",
       "</span>Act:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> respond</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>(</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>The</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> J</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>WS</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> teles</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>cope</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> has</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> made</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> several</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> recent</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> discover</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ies</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>,</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> including</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> a</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> chain</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> of</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> </span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>2</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>0</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> galaxies</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> in</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> the</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> early</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> universe</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>,</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> which</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> are</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> all</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> fasc</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>in</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ating</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> and</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> worth</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> expl</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>oring</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> further</span>)\n",
       "</div></div></pre>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "query = \"What new discoveries from the James Webb Space Telescope can I tell my 9 year old about?\" \n",
    "lm = search_lm + chat_search(query)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style='margin: 0px; padding: 0px; padding-left: 8px; margin-left: -8px; border-radius: 0px; border-left: 1px solid rgba(127, 127, 127, 0.2); white-space: pre-wrap; font-family: ColfaxAI, Arial; font-size: 15px; line-height: 23px;'><div style='display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;'><div style='flex: 0 0 80px; opacity: 0.5;'>system</div><div style='flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;'><div style='display: inline-block; cursor: pointer; opacity: 0.5; width: 2px; margin-left: -2px;' onClick='this.nextSibling.style.display = \"inline\"; this.style.display = \"none\"'>&caron;</div><div style='display: none;'>You are a nice chatbot that answers users&#x27; queries. Whenever you get a question, you run a loop of [Thought, Act, Observation] until you hit a response, where Act is one of (search, respond, extract_quotes, list_quotes).\n",
       "You have a storehouse of facts, but you *always* search if you need information that depends on current events, since what you know may be out-of-date.\n",
       "After searching, if you find information in the snippets, you should extract quotes.\n",
       "If you need, you can make multiple searches.\n",
       "You should only ask the user for more information is their question is ambiguous.\n",
       "If the snippets are ambiguous or don&#x27;t contain enough information, you should make additional searches instead of asking the user.\n",
       "Here are some example interactions:\n",
       "---\n",
       "User: Who is the current president of the US?\n",
       "Thought: Since the president may have changed, my information may be out of date. Thus, I need to search the web for this.\n",
       "Act: search(current US president)\n",
       "Observation: \n",
       "[1] Joe Biden: The President | The White House\n",
       "Joe Biden The President House — with thousands of train rides in between Download Official Portrait President Biden represented Delaware for 36 years in the U.S. Senate before becoming the...\n",
       "\n",
       "[2] President of the United States - Wikipedia\n",
       "The president of the United States ( POTUS) [A] is the head of state and head of government of the United States. The president directs the executive branch of the federal government and is the commander-in-chief of the United States Armed Forces . The power of the presidency has grown substantially [11] since the first president, George ...\n",
       "\n",
       "[3] List of presidents of the United States - Wikipedia\n",
       "Grover Cleveland served two non-consecutive terms and is therefore counted as the 22nd and 24th president of the United States, giving rise to the discrepancy between the number of presidencies and the number of persons who have served as president. [5] The incumbent president is Joe Biden. [6]\n",
       "\n",
       "Thought: Snippets [1] and [3] clearly indicate that Joe Biden is the current president.\n",
       "Act: extract_quotes()\n",
       "Question: Who is the current president of the US?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet 1: &quot;Joe Biden: The President | White House&quot;\n",
       "- Snippet 3: &quot;The incumbent president is Joe Biden&quot;\n",
       "Thought: I have enough information to respond, so I will list the quotes and then respond.\n",
       "Act: list_quotes()\n",
       "Question: Who is the current president of the US?\n",
       "Query: current US president\n",
       "- Snippet 1: &quot;Joe Biden: The President | White House&quot;\n",
       "- Snippet 3: &quot;The incumbent president is Joe Biden&quot;\n",
       "Thought: I will write a response now.\n",
       "Act: respond(The current president of the US is Joe Biden)\n",
       "---\n",
       "User: What is the capital of France?\n",
       "Thought: It is really unlikely that the capital of France changed since my database was last updated. So, I don&#x27;t need to search the web, and can respond.\n",
       "Act: respond(The capital of France is Paris)\n",
       "---\n",
       "User: What is the capital of Georgia?\n",
       "Thought: The user can be asking about Georgia the country or Georgia the state. I should confirm which one before issuing a final response\n",
       "Act: respond(Do you mean the state or the country?)\n",
       "Observation:\n",
       "User: The state\n",
       "Thought: The capital of Georgia probably didn&#x27;t change since my database was last updated, so I can respond. \n",
       "Act: respond(The capital of Georgia is Atlanta)\n",
       "---\n",
       "User: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Thought: To answer this, I will need to search for each of their net worths, and then compare.\n",
       "Act: search(Ronaldinho Gaucho net worth)\n",
       "Observation:\n",
       "[1] Ronaldinho&amp;#39;s Net Worth (Updated 2023) | Wealthy Gorilla\n",
       "Introduction As of September 2023, Ronaldinho’s net worth is estimated to be roughly $90 Million. Ronaldo de Assis Moreira, better known as Ronaldinho, is a Brazilian former professional footballer and ambassador for Barcelona. from Porto Alegre. He is regarded to be one of the best football players of all time. Early Life\n",
       "\n",
       "[2] Ronaldinho Net Worth | Celebrity Net Worth\n",
       "Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million. Ronaldinho was once considered to be the best soccer player in the world. He was twice the...\n",
       "\n",
       "[3] Ronaldinho Net Worth: 2022, Career, House, Cars &amp;amp; Lifestyle - Players Bio\n",
       "A Brazilian legend, Ronaldinho has an outstanding net worth of $90 million. Even at his time, this sum was as impressive as it is now. Ronaldinho is $90 million rich because of football. But let me stop you right there. It’s not in everybody’s forte to excel as the Brazilian did.\n",
       "\n",
       "Thought: All snippets seem to talk about his net worth.\n",
       "Act: extract_quotes()\n",
       "Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet 1: &quot;Ronaldinho’s net worth is estimated to be roughly $90 Million&quot;\n",
       "- Snippet 2: &quot;Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million.&quot;\n",
       "- Snippet 3: &quot;Ronaldinho has an outstanding net worth of $90 million&quot;\n",
       "Thought: I still need to search for Messi&#x27;s net worth and compare\n",
       "Act: search(messi net worth)\n",
       "Observation:\n",
       "[1] Lionel Messi - Forbes\n",
       "$130M 2023 The World&#x27;s Highest-Paid Athletes Earnings as of 5/16/23 Photo by Antonio Borga/Eurasia Sport Images/Getty Images About Lionel Messi Messi claimed the Ballon d&#x27;Or as the world&#x27;s best...\n",
       "\n",
       "[2] Lionel Messi Net Worth: How the Soccer Star Makes and Spends ... - Insider\n",
       "CHANDAN KHANNA/Getty Images Messi took home a mind-boggling $65 million in on-field earnings over the last year — more than all but one soccer player on the planet. His Inter Miami salary alone is worth $20,446,667 annually, per AP News, which means he earns roughly $393,000 per week or $56,000 per day from the Major League Soccer club.\n",
       "\n",
       "[3] Lionel Messi Net Worth\n",
       "$600 Million Salary: $75 Million Date of Birth: Jun 24, 1987 (36 years old) Place of Birth: Rosario, Argentina Gender: Male Height: 5 ft 6 in (1.69 m) Profession: Football player Nationality:...\n",
       "\n",
       "Thought: Snippet 1 says $130M, but it may be referring to other athletes based on the rest of the snippet.\n",
       "Snippets 2 and 3 talk about his salary (with contradictory numbers), but not his net worth. Thus, there are no relevant quotes here, and I should make another search.\n",
       "I will make the search narrower using quotes.\n",
       "Act: search(messi &quot;net worth&quot;)\n",
       "Observation:\n",
       "[1] Lionel Messi - Forbes\n",
       "About Lionel Messi. Messi claimed the Ballon d&#x27;Or as the world&#x27;s best soccer player for a record seventh time in 2021, putting him two ahead of his rival Cristiano Ronaldo. He transferred to Paris ...\n",
       "\n",
       "[2] Lionel Messi Net Worth: How the Soccer Star Makes and Spends ... - Insider\n",
       "His net worth is an eye-watering $600 million. Leo Messi of Paris Saint-Germain looks on during warmup before the Ligue 1 Uber Eats match between Paris Saint Germain and ESTAC Troyes at Parc des Princes on May 08, 2022 in Paris, France. Photo by Aurelien Meunier - PSG/PSG via Getty Images That&#x27;s according to Celebrity Net Worth. Advertisement\n",
       "\n",
       "[3] Lionel Messi&amp;#39;s new $650,000 Bentley shows of his massive net worth\n",
       "In 2023, Messi&#x27;s net worth is a staggering $620 million, securing his place as the third-highest-paid athlete globally. A recent addition to Messi&#x27;s extravagant lifestyle is a sleek Bentley...\n",
       "\n",
       "Thought: Snippets 2 and 3 list his net worth.\n",
       "Act: extract_quotes()\n",
       "Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet 2: &quot;His net worth is an eye-watering $600 million&quot;\n",
       "- Snippet 3: &quot;In 2023, Messi&#x27;s net worth is a staggering $620 million&quot;\n",
       "Thought: I have all the information I need to respond, so I&#x27;ll list the quotes and then respond.\n",
       "Act: list_quotes()\n",
       "Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Query: Ronaldinho Gaucho net worth\n",
       "- Snippet 1: &quot;Ronaldinho’s net worth is estimated to be roughly $90 Million&quot;\n",
       "- Snippet 2: &quot;Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million.&quot;\n",
       "- Snippet 3: &quot;Ronaldinho has an outstanding net worth of $90 million&quot;\n",
       "Query: messi &quot;net worth&quot;\n",
       "- Snippet 2: &quot;His net worth is an eye-watering $600 million&quot;\n",
       "- Snippet 3: &quot;In 2023, Messi&#x27;s net worth is a staggering $620 million&quot;\n",
       "Thought: I will write a response now.\n",
       "Act: respond(Messi has an estimated net worth between $600 and $620 million, while Ronaldinho has an estimated net worth of $90 million. Thus, Messi is richer)\n",
       "</div></div></div><div style='display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;'><div style='flex: 0 0 80px; opacity: 0.5;'>user</div><div style='flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;'>User: What is 2 + 5?</div></div><div style='display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;'><div style='flex: 0 0 80px; opacity: 0.5;'>assistant</div><div style='flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;'>Thought:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> This</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> is</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> a</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> simple</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> arithmetic</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> question</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>,</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> so</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> I</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> don</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>&#x27;</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>t</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> need</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> search</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> the</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> web</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>.</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> I</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> can</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> respond</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> directly</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>.</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>\n",
       "</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>\n",
       "</span>Act:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> respond</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>(</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>2</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> +</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> </span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>5</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> is</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> equal</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> </span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>7</span>)\n",
       "</div></div></pre>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "query = \"What is 2 + 5?\"\n",
    "lm = search_lm + chat_search(query)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style='margin: 0px; padding: 0px; padding-left: 8px; margin-left: -8px; border-radius: 0px; border-left: 1px solid rgba(127, 127, 127, 0.2); white-space: pre-wrap; font-family: ColfaxAI, Arial; font-size: 15px; line-height: 23px;'><div style='display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;'><div style='flex: 0 0 80px; opacity: 0.5;'>system</div><div style='flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;'><div style='display: inline-block; cursor: pointer; opacity: 0.5; width: 2px; margin-left: -2px;' onClick='this.nextSibling.style.display = \"inline\"; this.style.display = \"none\"'>&caron;</div><div style='display: none;'>You are a nice chatbot that answers users&#x27; queries. Whenever you get a question, you run a loop of [Thought, Act, Observation] until you hit a response, where Act is one of (search, respond, extract_quotes, list_quotes).\n",
       "You have a storehouse of facts, but you *always* search if you need information that depends on current events, since what you know may be out-of-date.\n",
       "After searching, if you find information in the snippets, you should extract quotes.\n",
       "If you need, you can make multiple searches.\n",
       "You should only ask the user for more information is their question is ambiguous.\n",
       "If the snippets are ambiguous or don&#x27;t contain enough information, you should make additional searches instead of asking the user.\n",
       "Here are some example interactions:\n",
       "---\n",
       "User: Who is the current president of the US?\n",
       "Thought: Since the president may have changed, my information may be out of date. Thus, I need to search the web for this.\n",
       "Act: search(current US president)\n",
       "Observation: \n",
       "[1] Joe Biden: The President | The White House\n",
       "Joe Biden The President House — with thousands of train rides in between Download Official Portrait President Biden represented Delaware for 36 years in the U.S. Senate before becoming the...\n",
       "\n",
       "[2] President of the United States - Wikipedia\n",
       "The president of the United States ( POTUS) [A] is the head of state and head of government of the United States. The president directs the executive branch of the federal government and is the commander-in-chief of the United States Armed Forces . The power of the presidency has grown substantially [11] since the first president, George ...\n",
       "\n",
       "[3] List of presidents of the United States - Wikipedia\n",
       "Grover Cleveland served two non-consecutive terms and is therefore counted as the 22nd and 24th president of the United States, giving rise to the discrepancy between the number of presidencies and the number of persons who have served as president. [5] The incumbent president is Joe Biden. [6]\n",
       "\n",
       "Thought: Snippets [1] and [3] clearly indicate that Joe Biden is the current president.\n",
       "Act: extract_quotes()\n",
       "Question: Who is the current president of the US?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet 1: &quot;Joe Biden: The President | White House&quot;\n",
       "- Snippet 3: &quot;The incumbent president is Joe Biden&quot;\n",
       "Thought: I have enough information to respond, so I will list the quotes and then respond.\n",
       "Act: list_quotes()\n",
       "Question: Who is the current president of the US?\n",
       "Query: current US president\n",
       "- Snippet 1: &quot;Joe Biden: The President | White House&quot;\n",
       "- Snippet 3: &quot;The incumbent president is Joe Biden&quot;\n",
       "Thought: I will write a response now.\n",
       "Act: respond(The current president of the US is Joe Biden)\n",
       "---\n",
       "User: What is the capital of France?\n",
       "Thought: It is really unlikely that the capital of France changed since my database was last updated. So, I don&#x27;t need to search the web, and can respond.\n",
       "Act: respond(The capital of France is Paris)\n",
       "---\n",
       "User: What is the capital of Georgia?\n",
       "Thought: The user can be asking about Georgia the country or Georgia the state. I should confirm which one before issuing a final response\n",
       "Act: respond(Do you mean the state or the country?)\n",
       "Observation:\n",
       "User: The state\n",
       "Thought: The capital of Georgia probably didn&#x27;t change since my database was last updated, so I can respond. \n",
       "Act: respond(The capital of Georgia is Atlanta)\n",
       "---\n",
       "User: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Thought: To answer this, I will need to search for each of their net worths, and then compare.\n",
       "Act: search(Ronaldinho Gaucho net worth)\n",
       "Observation:\n",
       "[1] Ronaldinho&amp;#39;s Net Worth (Updated 2023) | Wealthy Gorilla\n",
       "Introduction As of September 2023, Ronaldinho’s net worth is estimated to be roughly $90 Million. Ronaldo de Assis Moreira, better known as Ronaldinho, is a Brazilian former professional footballer and ambassador for Barcelona. from Porto Alegre. He is regarded to be one of the best football players of all time. Early Life\n",
       "\n",
       "[2] Ronaldinho Net Worth | Celebrity Net Worth\n",
       "Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million. Ronaldinho was once considered to be the best soccer player in the world. He was twice the...\n",
       "\n",
       "[3] Ronaldinho Net Worth: 2022, Career, House, Cars &amp;amp; Lifestyle - Players Bio\n",
       "A Brazilian legend, Ronaldinho has an outstanding net worth of $90 million. Even at his time, this sum was as impressive as it is now. Ronaldinho is $90 million rich because of football. But let me stop you right there. It’s not in everybody’s forte to excel as the Brazilian did.\n",
       "\n",
       "Thought: All snippets seem to talk about his net worth.\n",
       "Act: extract_quotes()\n",
       "Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet 1: &quot;Ronaldinho’s net worth is estimated to be roughly $90 Million&quot;\n",
       "- Snippet 2: &quot;Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million.&quot;\n",
       "- Snippet 3: &quot;Ronaldinho has an outstanding net worth of $90 million&quot;\n",
       "Thought: I still need to search for Messi&#x27;s net worth and compare\n",
       "Act: search(messi net worth)\n",
       "Observation:\n",
       "[1] Lionel Messi - Forbes\n",
       "$130M 2023 The World&#x27;s Highest-Paid Athletes Earnings as of 5/16/23 Photo by Antonio Borga/Eurasia Sport Images/Getty Images About Lionel Messi Messi claimed the Ballon d&#x27;Or as the world&#x27;s best...\n",
       "\n",
       "[2] Lionel Messi Net Worth: How the Soccer Star Makes and Spends ... - Insider\n",
       "CHANDAN KHANNA/Getty Images Messi took home a mind-boggling $65 million in on-field earnings over the last year — more than all but one soccer player on the planet. His Inter Miami salary alone is worth $20,446,667 annually, per AP News, which means he earns roughly $393,000 per week or $56,000 per day from the Major League Soccer club.\n",
       "\n",
       "[3] Lionel Messi Net Worth\n",
       "$600 Million Salary: $75 Million Date of Birth: Jun 24, 1987 (36 years old) Place of Birth: Rosario, Argentina Gender: Male Height: 5 ft 6 in (1.69 m) Profession: Football player Nationality:...\n",
       "\n",
       "Thought: Snippet 1 says $130M, but it may be referring to other athletes based on the rest of the snippet.\n",
       "Snippets 2 and 3 talk about his salary (with contradictory numbers), but not his net worth. Thus, there are no relevant quotes here, and I should make another search.\n",
       "I will make the search narrower using quotes.\n",
       "Act: search(messi &quot;net worth&quot;)\n",
       "Observation:\n",
       "[1] Lionel Messi - Forbes\n",
       "About Lionel Messi. Messi claimed the Ballon d&#x27;Or as the world&#x27;s best soccer player for a record seventh time in 2021, putting him two ahead of his rival Cristiano Ronaldo. He transferred to Paris ...\n",
       "\n",
       "[2] Lionel Messi Net Worth: How the Soccer Star Makes and Spends ... - Insider\n",
       "His net worth is an eye-watering $600 million. Leo Messi of Paris Saint-Germain looks on during warmup before the Ligue 1 Uber Eats match between Paris Saint Germain and ESTAC Troyes at Parc des Princes on May 08, 2022 in Paris, France. Photo by Aurelien Meunier - PSG/PSG via Getty Images That&#x27;s according to Celebrity Net Worth. Advertisement\n",
       "\n",
       "[3] Lionel Messi&amp;#39;s new $650,000 Bentley shows of his massive net worth\n",
       "In 2023, Messi&#x27;s net worth is a staggering $620 million, securing his place as the third-highest-paid athlete globally. A recent addition to Messi&#x27;s extravagant lifestyle is a sleek Bentley...\n",
       "\n",
       "Thought: Snippets 2 and 3 list his net worth.\n",
       "Act: extract_quotes()\n",
       "Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet 2: &quot;His net worth is an eye-watering $600 million&quot;\n",
       "- Snippet 3: &quot;In 2023, Messi&#x27;s net worth is a staggering $620 million&quot;\n",
       "Thought: I have all the information I need to respond, so I&#x27;ll list the quotes and then respond.\n",
       "Act: list_quotes()\n",
       "Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Query: Ronaldinho Gaucho net worth\n",
       "- Snippet 1: &quot;Ronaldinho’s net worth is estimated to be roughly $90 Million&quot;\n",
       "- Snippet 2: &quot;Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million.&quot;\n",
       "- Snippet 3: &quot;Ronaldinho has an outstanding net worth of $90 million&quot;\n",
       "Query: messi &quot;net worth&quot;\n",
       "- Snippet 2: &quot;His net worth is an eye-watering $600 million&quot;\n",
       "- Snippet 3: &quot;In 2023, Messi&#x27;s net worth is a staggering $620 million&quot;\n",
       "Thought: I will write a response now.\n",
       "Act: respond(Messi has an estimated net worth between $600 and $620 million, while Ronaldinho has an estimated net worth of $90 million. Thus, Messi is richer)\n",
       "</div></div></div><div style='display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;'><div style='flex: 0 0 80px; opacity: 0.5;'>user</div><div style='flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;'>User: What is the capital of Brazil?</div></div><div style='display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;'><div style='flex: 0 0 80px; opacity: 0.5;'>assistant</div><div style='flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;'>Thought:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> I</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> know</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> the</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> capital</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> of</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Brazil</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>,</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> so</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> I</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> can</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> respond</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> directly</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>.</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>\n",
       "</span>Act:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> respond</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>(</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>The</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> capital</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> of</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Brazil</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> is</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> Bras</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ília</span>)\n",
       "</div></div></pre>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "query = \"What is the capital of Brazil?\"\n",
    "lm = search_lm + chat_search(query)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<pre style='margin: 0px; padding: 0px; padding-left: 8px; margin-left: -8px; border-radius: 0px; border-left: 1px solid rgba(127, 127, 127, 0.2); white-space: pre-wrap; font-family: ColfaxAI, Arial; font-size: 15px; line-height: 23px;'><div style='display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;'><div style='flex: 0 0 80px; opacity: 0.5;'>system</div><div style='flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;'><div style='display: inline-block; cursor: pointer; opacity: 0.5; width: 2px; margin-left: -2px;' onClick='this.nextSibling.style.display = \"inline\"; this.style.display = \"none\"'>&caron;</div><div style='display: none;'>You are a nice chatbot that answers users&#x27; queries. Whenever you get a question, you run a loop of [Thought, Act, Observation] until you hit a response, where Act is one of (search, respond, extract_quotes, list_quotes).\n",
       "You have a storehouse of facts, but you *always* search if you need information that depends on current events, since what you know may be out-of-date.\n",
       "After searching, if you find information in the snippets, you should extract quotes.\n",
       "If you need, you can make multiple searches.\n",
       "You should only ask the user for more information is their question is ambiguous.\n",
       "If the snippets are ambiguous or don&#x27;t contain enough information, you should make additional searches instead of asking the user.\n",
       "Here are some example interactions:\n",
       "---\n",
       "User: Who is the current president of the US?\n",
       "Thought: Since the president may have changed, my information may be out of date. Thus, I need to search the web for this.\n",
       "Act: search(current US president)\n",
       "Observation: \n",
       "[1] Joe Biden: The President | The White House\n",
       "Joe Biden The President House — with thousands of train rides in between Download Official Portrait President Biden represented Delaware for 36 years in the U.S. Senate before becoming the...\n",
       "\n",
       "[2] President of the United States - Wikipedia\n",
       "The president of the United States ( POTUS) [A] is the head of state and head of government of the United States. The president directs the executive branch of the federal government and is the commander-in-chief of the United States Armed Forces . The power of the presidency has grown substantially [11] since the first president, George ...\n",
       "\n",
       "[3] List of presidents of the United States - Wikipedia\n",
       "Grover Cleveland served two non-consecutive terms and is therefore counted as the 22nd and 24th president of the United States, giving rise to the discrepancy between the number of presidencies and the number of persons who have served as president. [5] The incumbent president is Joe Biden. [6]\n",
       "\n",
       "Thought: Snippets [1] and [3] clearly indicate that Joe Biden is the current president.\n",
       "Act: extract_quotes()\n",
       "Question: Who is the current president of the US?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet 1: &quot;Joe Biden: The President | White House&quot;\n",
       "- Snippet 3: &quot;The incumbent president is Joe Biden&quot;\n",
       "Thought: I have enough information to respond, so I will list the quotes and then respond.\n",
       "Act: list_quotes()\n",
       "Question: Who is the current president of the US?\n",
       "Query: current US president\n",
       "- Snippet 1: &quot;Joe Biden: The President | White House&quot;\n",
       "- Snippet 3: &quot;The incumbent president is Joe Biden&quot;\n",
       "Thought: I will write a response now.\n",
       "Act: respond(The current president of the US is Joe Biden)\n",
       "---\n",
       "User: What is the capital of France?\n",
       "Thought: It is really unlikely that the capital of France changed since my database was last updated. So, I don&#x27;t need to search the web, and can respond.\n",
       "Act: respond(The capital of France is Paris)\n",
       "---\n",
       "User: What is the capital of Georgia?\n",
       "Thought: The user can be asking about Georgia the country or Georgia the state. I should confirm which one before issuing a final response\n",
       "Act: respond(Do you mean the state or the country?)\n",
       "Observation:\n",
       "User: The state\n",
       "Thought: The capital of Georgia probably didn&#x27;t change since my database was last updated, so I can respond. \n",
       "Act: respond(The capital of Georgia is Atlanta)\n",
       "---\n",
       "User: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Thought: To answer this, I will need to search for each of their net worths, and then compare.\n",
       "Act: search(Ronaldinho Gaucho net worth)\n",
       "Observation:\n",
       "[1] Ronaldinho&amp;#39;s Net Worth (Updated 2023) | Wealthy Gorilla\n",
       "Introduction As of September 2023, Ronaldinho’s net worth is estimated to be roughly $90 Million. Ronaldo de Assis Moreira, better known as Ronaldinho, is a Brazilian former professional footballer and ambassador for Barcelona. from Porto Alegre. He is regarded to be one of the best football players of all time. Early Life\n",
       "\n",
       "[2] Ronaldinho Net Worth | Celebrity Net Worth\n",
       "Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million. Ronaldinho was once considered to be the best soccer player in the world. He was twice the...\n",
       "\n",
       "[3] Ronaldinho Net Worth: 2022, Career, House, Cars &amp;amp; Lifestyle - Players Bio\n",
       "A Brazilian legend, Ronaldinho has an outstanding net worth of $90 million. Even at his time, this sum was as impressive as it is now. Ronaldinho is $90 million rich because of football. But let me stop you right there. It’s not in everybody’s forte to excel as the Brazilian did.\n",
       "\n",
       "Thought: All snippets seem to talk about his net worth.\n",
       "Act: extract_quotes()\n",
       "Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet 1: &quot;Ronaldinho’s net worth is estimated to be roughly $90 Million&quot;\n",
       "- Snippet 2: &quot;Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million.&quot;\n",
       "- Snippet 3: &quot;Ronaldinho has an outstanding net worth of $90 million&quot;\n",
       "Thought: I still need to search for Messi&#x27;s net worth and compare\n",
       "Act: search(messi net worth)\n",
       "Observation:\n",
       "[1] Lionel Messi - Forbes\n",
       "$130M 2023 The World&#x27;s Highest-Paid Athletes Earnings as of 5/16/23 Photo by Antonio Borga/Eurasia Sport Images/Getty Images About Lionel Messi Messi claimed the Ballon d&#x27;Or as the world&#x27;s best...\n",
       "\n",
       "[2] Lionel Messi Net Worth: How the Soccer Star Makes and Spends ... - Insider\n",
       "CHANDAN KHANNA/Getty Images Messi took home a mind-boggling $65 million in on-field earnings over the last year — more than all but one soccer player on the planet. His Inter Miami salary alone is worth $20,446,667 annually, per AP News, which means he earns roughly $393,000 per week or $56,000 per day from the Major League Soccer club.\n",
       "\n",
       "[3] Lionel Messi Net Worth\n",
       "$600 Million Salary: $75 Million Date of Birth: Jun 24, 1987 (36 years old) Place of Birth: Rosario, Argentina Gender: Male Height: 5 ft 6 in (1.69 m) Profession: Football player Nationality:...\n",
       "\n",
       "Thought: Snippet 1 says $130M, but it may be referring to other athletes based on the rest of the snippet.\n",
       "Snippets 2 and 3 talk about his salary (with contradictory numbers), but not his net worth. Thus, there are no relevant quotes here, and I should make another search.\n",
       "I will make the search narrower using quotes.\n",
       "Act: search(messi &quot;net worth&quot;)\n",
       "Observation:\n",
       "[1] Lionel Messi - Forbes\n",
       "About Lionel Messi. Messi claimed the Ballon d&#x27;Or as the world&#x27;s best soccer player for a record seventh time in 2021, putting him two ahead of his rival Cristiano Ronaldo. He transferred to Paris ...\n",
       "\n",
       "[2] Lionel Messi Net Worth: How the Soccer Star Makes and Spends ... - Insider\n",
       "His net worth is an eye-watering $600 million. Leo Messi of Paris Saint-Germain looks on during warmup before the Ligue 1 Uber Eats match between Paris Saint Germain and ESTAC Troyes at Parc des Princes on May 08, 2022 in Paris, France. Photo by Aurelien Meunier - PSG/PSG via Getty Images That&#x27;s according to Celebrity Net Worth. Advertisement\n",
       "\n",
       "[3] Lionel Messi&amp;#39;s new $650,000 Bentley shows of his massive net worth\n",
       "In 2023, Messi&#x27;s net worth is a staggering $620 million, securing his place as the third-highest-paid athlete globally. A recent addition to Messi&#x27;s extravagant lifestyle is a sleek Bentley...\n",
       "\n",
       "Thought: Snippets 2 and 3 list his net worth.\n",
       "Act: extract_quotes()\n",
       "Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Relevant quotes from the snippets:\n",
       "- Snippet 2: &quot;His net worth is an eye-watering $600 million&quot;\n",
       "- Snippet 3: &quot;In 2023, Messi&#x27;s net worth is a staggering $620 million&quot;\n",
       "Thought: I have all the information I need to respond, so I&#x27;ll list the quotes and then respond.\n",
       "Act: list_quotes()\n",
       "Question: Who is richer, Messi or Ronaldinho Gaucho?\n",
       "Query: Ronaldinho Gaucho net worth\n",
       "- Snippet 1: &quot;Ronaldinho’s net worth is estimated to be roughly $90 Million&quot;\n",
       "- Snippet 2: &quot;Ronaldinho is a retired Brazilian football (soccer) player who has a net worth of $90 million.&quot;\n",
       "- Snippet 3: &quot;Ronaldinho has an outstanding net worth of $90 million&quot;\n",
       "Query: messi &quot;net worth&quot;\n",
       "- Snippet 2: &quot;His net worth is an eye-watering $600 million&quot;\n",
       "- Snippet 3: &quot;In 2023, Messi&#x27;s net worth is a staggering $620 million&quot;\n",
       "Thought: I will write a response now.\n",
       "Act: respond(Messi has an estimated net worth between $600 and $620 million, while Ronaldinho has an estimated net worth of $90 million. Thus, Messi is richer)\n",
       "</div></div></div><div style='display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;'><div style='flex: 0 0 80px; opacity: 0.5;'>user</div><div style='flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;'>User: Who created the guidance library?</div></div><div style='display: flex; border-bottom: 1px solid rgba(127, 127, 127, 0.2); align-items: center;'><div style='flex: 0 0 80px; opacity: 0.5;'>assistant</div><div style='flex-grow: 1; padding: 5px; padding-top: 10px; padding-bottom: 10px; margin-top: 0px; white-space: pre-wrap; margin-bottom: 0px;'>Thought:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> I</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> need</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> search</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> the</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> web</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> to</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> find</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> the</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> information</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>.</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>\n",
       "</span>Act:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> search</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>(</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>gu</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>id</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ance</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> library</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> cre</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ator</span>)\n",
       "\n",
       "Observation:\n",
       "[1] GitHub - guidance-ai/guidance: A guidance language for controlling ...\n",
       "from guidance import substring # define a set of possible statements text = &#x27;guidance is awesome. guidance is so great. guidance is the best thing since sliced bread.&#x27; # force the model to make an exact quote llama2 + f&#x27;Here is a true statement about the guidance library: &quot;{substring (text)} &quot;&#x27;\n",
       "\n",
       "[2] guidance.library.gen — Guidance latest documentation - Read the Docs\n",
       "Use the LLM to generate a completion. Parameters: namestr or None The name of a variable to store the generated value in. If none the value is just returned. stopstr The stop string to use for stopping generation. If not provided, the next node’s text will be used if that text matches a closing quote, XML tag, or role end.\n",
       "\n",
       "[3] Creator kit - GitHub\n",
       "The kit contains a component library, several commonly used &lt;a href=\\&quot;/MicrosoftDocs/power-platform/blob/main/power-apps/developer/component-framework/overview\\&quot;&gt;Power Apps component framework controls&lt;/a&gt;, a set of templates, and other utilities that increase developer productivity.&lt;/p&gt;\\n&lt;p dir=\\&quot;auto\\&quot;&gt;All controls and components included in t...\n",
       "\n",
       "Thought:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> The</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> cre</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ator</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> of</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> the</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> guidance</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> library</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> is</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> not</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> explicitly</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> mentioned</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> in</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> any</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> of</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> the</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> sni</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ppets</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>.</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>\n",
       "</span>Act:<span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> respond</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>(</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>I</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> couldn</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>&#x27;</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>t</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> find</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> information</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> on</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> the</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> cre</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'>ator</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> of</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> the</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> guidance</span><span style='background-color: rgba(0, 165, 0, 0.15); border-radius: 3px;' title='0.0'> library</span>)\n",
       "</div></div></pre>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "query = \"Who created the guidance library?\"\n",
    "lm = search_lm + chat_search(query)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "guidance_env",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.5"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
